2005-03-05 Hidetoshi NAGAI * ext/tk/lib/tkextlib/tile.rb: lack of "autoload TProgressbar" 2005-03-05 Hidetoshi NAGAI * ext/tk/lib/tkextlib/tile.rb: support tile-0.6 * ext/tk/lib/tkextlib/tile/tbutton.rb: ditto * ext/tk/lib/tkextlib/tile/tcheckbutton.rb: ditto * ext/tk/lib/tkextlib/tile/tlabel.rb: ditto * ext/tk/lib/tkextlib/tile/tmenubutton.rb: ditto * ext/tk/lib/tkextlib/tile/tnotebook.rb: ditto * ext/tk/lib/tkextlib/tile/tradiobutton.rb: ditto * ext/tk/lib/tkextlib/tile/tcombobox.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tentry.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tframe.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tlabelframe.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tprogressbar.rb: [new] ditto * ext/tk/lib/tkextlib/tile/treeview.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tscrollbar.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tseparator.rb: [new] ditto * ext/tk/lib/tkextlib/tile/tsquare.rb: [new] ditto 2005-02-20 Hidetoshi NAGAI * ext/tk/lib/tkextlib/tclx/tclx.rb: warning TclX's 'signal' command. 2005-01-25 Hidetoshi NAGAI * ext/tk/lib/tkextlib/blt/component.rb: bug fix. cannot accept a callback ID string for a command argument. [ruby-dev:25479] * ext/tk/lib/tkextlib/blt/tabset.rb: ditto * ext/tk/lib/tkextlib/blt/treeview.rb: ditto * ext/tk/lib/tkextlib/bwidget/labelentry.rb: ditto * ext/tk/lib/tkextlib/bwidget/listbox.rb: ditto * ext/tk/lib/tkextlib/bwidget/notebook.rb: ditto * ext/tk/lib/tkextlib/bwidget/spinbox.rb: ditto * ext/tk/lib/tkextlib/bwidget/tree.rb: ditto * ext/tk/lib/tkextlib/itk/incr_tk.rb: ditto * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb: ditto * ext/tk/lib/tkextlib/tkDND/tkdnd.rb: ditto * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: ditto * ext/tk/sample/tkHTML/ss.rb: local variable scope bug fix [ruby-dev:25479] * ext/tk/sample/vu/vu_demo.rb: rename from vu.rb; avoid the bug on Windows version of Tcl/Tk. The trouble based on the bug occurs when the script name (without extension) is a same name as a Tcl/Tk's library file name (without extension) required in the script. 2004-12-24 Hidetoshi NAGAI * add BLT extension support 2004-12-16 Hidetoshi NAGAI * bwidget/labelentry.rb: use TkCore.callback_obj?() * bwidget/listbox.rb: ditto * bwidget/notebook.rb: ditto * bwidget/spinbox.rb: ditto * itk/incr_tk.rb: ditto * iwidgets/scrolledcanvas.rb: ditto * tkDND/tkdnd.rb: ditto * treectrl/tktreectrl.rb: ditto * winico/winico.rb: ditto 2004-12-10 Hidetoshi NAGAI * tile/style.rb: 'theme_use' method bug fix 2004-12-08 Hidetoshi NAGAI * bwidget/notebook.rb: raise method cannot return the raised page. * bwidget/labelentry.rb: bind methods accept subst_args + block * bwidget/listbox.rb: ditto * bwidget/notebook.rb: ditto * bwidget/spinbox.rb: ditto * bwidget/tree.rb: ditto * itk/incr_tk.rb: ditto * iwidgets/scrolledcanvas.rb: ditto * tkDND/tkdnd.rb: ditto * treectrl/tktreectrl.rb: ditto 2004-11-26 Hidetoshi NAGAI * bwidget/notebook.rb: uses epath * bwidget/widget.rb: ditto * tktable/tktable.rb: ditto * tcllib/cursor.rb: ditto, and bug fix 2004-11-10 Hidetoshi NAGAI * tile/style.rb: bug fix 2004-11-07 Hidetoshi NAGAI * iwidgets/scrolledcanvas.rb: bind-event methods accept multi substitution arguments. * tktable/tktable.rb: ditto. * treectrl/tktreectrl.rb: ditto 2004-11-03 Hidetoshi NAGAI * SUPPORT_STATUS: BLT moves to 'plan to support' from 'not determined' * itk/incr_tk.rb: __cget_cmd and __config_cmd are private methods * tcllib/autoscroll.rb: extend TkCore * tcllib/cursor.rb: ditto. * tcllib/plotchart.rb: ditto. * tcllib/style.rb: ditto. * tile/style.rb: ditto. * tkDND/shape.rb: ditto. 2004-10-24 Hidetoshi NAGAI * bwidget/tree.rb: bug fix on Windows 2004-10-16 Hidetoshi NAGAI * tcllib/ico.rb: new library (Tk::Tcllib:ICO) * tcllib.rb: add Tk::Tcllib::ICO (based on tcllib 1.7) 2004-10-06 Hidetoshi NAGAI * bwidget.rb (BWidget.grab): bug fix * tcllib.rb: typo fix 2004-07-28 Hidetoshi NAGAI * add winico support 2004-07-23 Hidetoshi NAGAI * add TclX support (partially; infox command and XPG/3 MsgCat only) 2004-07-15 Hidetoshi NAGAI * bug fix * support TkTable extension 2004-07-12 Hidetoshi NAGAI * bug fix * support Iwidgets extension 2004-07-10 Hidetoshi NAGAI * bug fix * add more part of [incr Widget] support (about 65%? are complete) * use Tk::ValidateConfigure.__def_validcmd() method (new function to define validatecommand methods easier) * tcllib.rb : avoid the loading trouble that almost all part of the extension is not available when some libraries are invalid. 2004-07-09 Hidetoshi NAGAI * add some part of [incr Widget] support (about 50%? are complete) 2004-07-07 Hidetoshi NAGAI * add [incr Tck], [incr Tk] support 2004-07-06 Hidetoshi NAGAI * support BWidget extension * add BWidget extension demo * add ICONS extension demo * many bug fix 2004-07-01 Hidetoshi NAGAI * 1st release of tkextlib ( to support Tcl/Tk extensions ) 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
#+OPTIONS: ^:{}
#+EMAIL: abokovoy@redhat.com
#+AUTHOR: Alexander Bokovoy
#+STYLE: <style type="text/css">
#+STYLE:  pre {
#+STYLE:     border: 1pt solid #000000;
#+STYLE:     background-color: #404040;
#+STYLE:     color: white;
#+STYLE:   }
#+STYLE: .src {width: 940px;}
#+STYLE: dt {width: 400px; margin 25px auto;}
#+STYLE: dd {width: 940px;}
#+STYLE: p {text-align:justify;}
#+STYLE: body {width: 960px;
#+STYLE:       margin: 0 auto;
#+STYLE:      }
#+STYLE: div#content {margin: 0 10px 0 10px;
#+STYLE:          display: inline;
#+STYLE:          float: left;
#+STYLE:          width: 940px;
#+STYLE:          overflow: hidden;}
#+STYLE: </style>
Extending FreeIPA
* Introduction
FreeIPA is an integrated security information management solution. There is a common
framework written in Python to command LDAP server provided by a 389-ds project, certificate
services of a Dogtag project, and a MIT Kerberos server, as well as configuring various other
services typically used to maintain integrity of an enterprise environment, like DNS and
time management (NTP). The framework is written in Python, runs at a server side, and
provides access via command line tools or web-based user interface.

As core parts of the framework are implemented as pluggable modules, it is possible to
extend FreeIPA on multiple levels. This document attempts to present general ideas and
ways to make use of most of extensibility points in FreeIPA.

For information management solutions extensibility could mean multiple things. Information
objects that are managed could be extended themselves or new objects could be added. New
operations on existing objects might become needed or certain aspects of an object should
be hidden in a specific environment. All these tasks may require quite different approaches
to implement.

Following chapters will cover high-level design of FreeIPA and dive into details of its core
framework. Knowledge of Python programming language basics is required. Understanding
LDAP concepts is desirable, though it is not required for simple
extensions as FreeIPA attempts to provide sufficient mapping of LDAP concepts onto less
complex structures and Python objects, lowering a barrier to fine tune FreeIPA for
the specific use cases.
* High level design
FreeIPA core is written in Python programming language. The data is stored in LDAP
database, and client-server paradigm is used for managing it. A FreeIPA server instance
runs its own LDAP database, provided by 389-ds project (formerly Fedora Directory
Server). A single instance of LDAP database corresponds to the single FreeIPA
domain. Access to all information stored in the database is provided via FreeIPA server
core which is run as a simple WSGI application which uses XML-RPC and JSON to exchange
requests with its own clients.

Multiple replicas of the FreeIPA instance can be created on different servers, they are
managed with the help of replication mechanisms of 389-ds directory server.

As LDAP database is used for data storage, LDAP's Access Control Model is used to provide
privilege separation and Kerberos tickets are used to pass-through assertion of
authenticity. As Kerberos server is using the same LDAP database instance, use of Kerberos
tickets allows to perform operations against the database on the server if a client is
capable to forward such tickets via communication channels selected for the operation.

When FreeIPA client connects to FreeIPA server, a Kerberos ticket is forwarded
to the server and operations against LDAP database are performed under identity
authenticated when the ticket was issued. As LDAP database also uses Kerberos to establish
identity of a client, Access Control Information attributes can be used to limit what
entries could be accessed and what operations could be performed.

The approach allows to delegate operations from a FreeIPA client to the FreeIPA server
and in general gives FreeIPA server ability to interact with any Kerberos-aware service on
behalf of the client. It also allows to keep FreeIPA client side implementation relatively
light-weight: all it needs to do is to be able to forward Kerberos ticket, process XML-RPC or
JSON, and present resulting responses to the user.

Besides run-time core, FreeIPA includes few configuration tools. These tools
are split between server and client. Server-side tools are used when an instance of
FreeIPA server is set up and configured, while client-side tools are used to configure client
systems. While the server tools are used to configure LDAP database, put proper schema
definitions in use, create Kerberos domain, Certificate Authority and configure all
corresponding services, client side is more limited to configure PAM/NSS modules to work
against FreeIPA server, and make sure that appropriate information about the client host
is recorded in FreeIPA databases.
* Core plug-in framework
FreeIPA core defines few fundamentals. These are managed objects, their properties, and
methods to apply actions to the objects. Methods, in turn, are commands that are
associated with a specific object. Additionally, there are commands that do not have
directly associated objects and may perform actions over few of those. Objects are stored
using data store represented by a back end, and one of most useful back ends is LDAP store
back end.

Altogether, set of =Object=, =Property=, =Method=, =Command=, and =Backend= instances
represent application programming interface, API, of FreeIPA core framework.

In Python programming language object oriented support is implemented using a fairly
simple concept that allows to modify instances in place, extending or removing their
properties and methods. While this concept is highly useful, in security-oriented
frameworks ability to lock down and trace origins of changes is also important. FreeIPA core
attempts to implement locking down feature by artificially making instances of foundation
classes read-only after their initialization has happened. If an attempt to modify object
happens after it was locked down, an exception is thrown. There are many classes
following this pattern.

For example, =ipalib.frontend.Command= class is derived from =ipalib.frontend.HasParam= class
that derives from =ipalib.plugable.Plugin= class which, in turn, is derived from
=ipalib.base.ReadOnly= class.

As result, every command has typed parameters and can dynamically be added to the
framework. At the same time, one cannot modify the properties of the command accidentally
once it is instantiated. This protects from modifications and enforces true nature of the
commands: they cannot have state that is carried over across multiple calls to the same
command unless the state is changing globally the whole environment around.

Environment also holds information about the context of execution. The /context/ is
important part of the FreeIPA framework as it also defines which methods of
the command instance are called in order to perform action. /Context/ in itself is defined
by the /environment/ which gives means to catch and store certain information about execution.
As with commands themselves, once instantiated, environment cannot be changed.

By default, for primary FreeIPA use, there are three major contexts defined: server,
client, and installer/updates.

- /server context/ :: plugins are registered and communicate with clients via XML-RPC and JSON
     listeners. They validate any arguments and options defined and then execute whatever
     action they supposed to perform
- /client context/ :: plugins are used to validate any arguments and options they take and
     then forward the request to the FreeIPA server.
- /installer context/, /updates context/ :: plugins specific to installation and update
     are loaded and registered. This context can be used to extend possible operations
     during set up of FreeIPA server.

A user may define any context they want. FreeIPA names server context as '~server~'. When
using the ~ipa~ command line tool the context is '~cli~'. Server installation tools, in
particular, '~ipa-ldap-updater~', use special '~updates~' context to load specialized
plugins useful during update of the installed FreeIPA server.

Because these utilities use the same framework they will do the same validation, set default
values, and perform other basic actions in all contexts. This can help to save a
round-trip when testing for invalid data. However, for client-server communication, the
server is always authoritative and can re-define what the client has sent.

** Name space
FreeIPA has one special type of read-only objects: =NameSpace=. =NameSpace= class gives an
ordered, immutable mapping object whose values can also be accessed as attributes. A
=NameSpace= instance is constructed from iterable providing its members, which are simply
arbitrary objects with =name= attribute. This attribute must conform to two following
rules:
- Its value must be unique among the members of the name space
- Its value must pass the =check_name()= function =ipalib.base= module.

=check_name()= function encodes a simple rule of a lower-case Python identifier that
neither starts nor ends with an underscore. Actual regular expression that codifies this
rule is =NAME_REGEX= within =ipalib.constants= module.

Once name space is created, it locks itself down and becomes read-only. It means that
while original objects accessed through the name space might change, the references to
them via name space will stay intact. They cannot be removed or changed to point to other
objects.

The name spaces are used widely in FreeIPA core framework. As mentioned earlier, API
includes set of objects, commands, and methods. Objects include properties that are
defined before lock-down. At object's lock-down parameters are placed into a name space
and that locks them down so that no parameter specification can change. Command's
parameters and options also locked down and cannot change once command instance is
instantiated.

** Parameters
=Param= class is used to define attributes, arguments, or options throughout FreeIPA core
framework. The =Param= base class is not used directly but rather sub-classed to define
properties like passwords or specific data types like =Str= or =Int=.

Instances of classes inherited from =Param= base class give uniform access to the
properties required to command line interface, Web UI, and internally to FreeIPA
code. Following properties are most important:
 - /name/ :: name of the parameter used internally to address the parameter in Python
             code. The /name/ could include special characters to designate a =Param= spec.
 - /cli_name/ :: optional name of the parameter to use in command line
                  interface. FreeIPA's CLI sets a mechanism to automatically translate
                  from a command line option name to a parameter's /name/ if /cli_name/
                  is specified.
 - /label/ :: A short phrase describing the parameter. It is used on the CLI when
              interactively prompting for the values, and as a label for the form inputs
              in the Web UI. The /label/ should start with an initial capital letter.
 - /doc/ :: A long description of the parameter. It is used by the CLI when displaying the
            help information for a command, and as an extra instruction for the form input
            on the Web UI. By default the /doc/ is the same as the /label/ but can be
            overridden when a =Param= instance is created. As with /label/, /doc/ should
            start with an initial capital letter and additionally should not end with any
            punctuation.
 - /required/ ::  If set to =True=, means this parameter is required to supply. All
                 parameters are required by default and that means that /required/
                 property should only be specified when parameter *is not required*.
 - /multivalue/ :: if set to =True=, means this parameter can accept a Python's tuple of
                   values. By default all parameters are *single-valued*.

When parameter /name/ has any of ~?~, ~*~, or ~+~ characters, it is treated as parameter
spec and is used to specify whether parameter is required, and should it be
multivalued. Following syntax is used:

| Spec   | Name  | Required | Multivalue |
|--------+-------+----------+------------|
| 'var'  | 'var' | True     | False      |
| 'var?' | 'var' | False    | False      |
| 'var*' | 'var' | False    | True       |
| 'var+' | 'var' | True     | True       |

Access to the value stored by the =Param= class is given through a callable interface:

#+BEGIN_SRC python
age = Int('age', label='Age', default=100)
print age(10)
#+END_SRC

Following parameter classes are defined and used throughout FreeIPA framework:
- /Bool/ :: boolean parameters that are stored in Python's ~bool~ type, therefore, they
            return either ~True~ or ~False~ value. However, they accept ~1~, ~True~
            (Python boolean), or Unicode strings '~1~', '~true~' and '~TRUE~' as truth value, and ~0~,
            ~False~ (Python boolean), or Unicode strings '~0~', '~false~', and '~FALSE~' as false.
- /Flag/ :: boolean parameters which always have default value. Property /default/ can be
            used to set the value. Defaults to ~False~:
#+BEGIN_SRC python
verbose = Flag('verbose', default=True)
#+END_SRC
- /Int/ :: integer parameters that are stored in Python's int type. Two additional properties can be
           specified when constructing =Int= parameter:
           - /minvalue/ :: minimal value that this parameter accepts, defaults to =MININT=
           - /maxvalue/ :: maximum value this parameter can accept, defaults to =MAXINT=
- /Decimal/ :: floating point parameters that are stored in Python's Decimal type. =Decimal= has
             the same two additional properties as =Int=. Unlike =Int=, there are no
             default values for the minimal and maximum boundaries.
- /Bytes/ :: a parameter to represent binary data.
- /Str/ :: parameter representing a Unicode text. Both /Bytes/ and /Str/ parameters accept
           following additional properties:
           - /minlength/ :: minimal length of the parameter
           - /maxlength/ :: maximum length of the parameter
           - /length/ :: length of the parameters
           - /pattern/ :: regular expression applied to the parameter's value to check its
                          validness
           - /pattern_errmsg/ :: an error message to show when regular expression check fails
- /IA5Str/ :: string parameter as defined by RFC 4517. It means all characters of the
              string must be ASCII characters (7-bit).
- /Password/ :: parameter to store passwords in Python =unicode= type. /Password/ has one
                additional property:
                - /confirm/ :: boolean specifying whether password should be confirmed
                               when entered. The confirmation is enabled by default.
- /Enum/ :: parameter can have one of predefined values that are specified with /values/
            property which is a Python's =tuple=.

For most common case of enumerable strings there are two parameters:
- /BytesEnum/ :: parameter value should be one of predefined =unicode= strings
- /StrEnum/ :: equivalent to /BytesEnum/. Originally /BytesEnum/ was stored in Python's
               =str= class instances but to be aligned with Python 3.0 changes both
               classes moved to store as =unicode=.

When more than one value should be accepted, there is /List/ parameter that allows to
provide list of strings separated by a separator, default to ','. Also, the /List/
parameter skips spaces before the next item in the list unless property /skipspace/ is set to False:
#+BEGIN_SRC python
names = List('names', separator=',', skipspace=True)
names_list = names(u'John Doe, John Lee, Brad Moe')
# names_list is (u'John Doe', u'John Lee', u'Brad Moe')