| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu services kerberos)
|
| 20 | #:use-module (gnu packages admin)
|
| 21 | #:use-module (gnu services)
|
| 22 | #:use-module (gnu services configuration)
|
| 23 | #:use-module (gnu system pam)
|
| 24 | #:use-module (guix gexp)
|
| 25 | #:use-module (guix records)
|
| 26 | #:use-module (srfi srfi-1)
|
| 27 | #:use-module (srfi srfi-34)
|
| 28 | #:use-module (srfi srfi-35)
|
| 29 | #:use-module (ice-9 match)
|
| 30 | #:export (pam-krb5-configuration
|
| 31 | pam-krb5-configuration?
|
| 32 | pam-krb5-service-type
|
| 33 |
|
| 34 | krb5-realm
|
| 35 | krb5-realm?
|
| 36 |
|
| 37 | krb5-configuration
|
| 38 | krb5-configuration?
|
| 39 | krb5-service-type))
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 | |
| 44 | (define unset-field (list 'unset-field))
|
| 45 |
|
| 46 | (define (predicate/unset pred)
|
| 47 | (lambda (x) (or (eq? x unset-field) (pred x))))
|
| 48 |
|
| 49 | (define string/unset? (predicate/unset string?))
|
| 50 | (define boolean/unset? (predicate/unset boolean?))
|
| 51 | (define integer/unset? (predicate/unset integer?))
|
| 52 |
|
| 53 | (define (uglify-field-name field-name)
|
| 54 | "Return FIELD-NAME with all instances of '-' replaced by '_' and any
|
| 55 | trailing '?' removed."
|
| 56 | (let ((str (symbol->string field-name)))
|
| 57 | (string-join (string-split (if (string-suffix? "?" str)
|
| 58 | (substring str 0 (1- (string-length str)))
|
| 59 | str)
|
| 60 | #\-)
|
| 61 | "_")))
|
| 62 |
|
| 63 | (define (serialize-field* field-name val)
|
| 64 | (format #t "~a = ~a\n" (uglify-field-name field-name) val))
|
| 65 |
|
| 66 | (define (serialize-string/unset field-name val)
|
| 67 | (unless (eq? val unset-field)
|
| 68 | (serialize-field* field-name val)))
|
| 69 |
|
| 70 | (define (serialize-integer/unset field-name val)
|
| 71 | (unless (eq? val unset-field)
|
| 72 | (serialize-field* field-name val)))
|
| 73 |
|
| 74 | (define (serialize-boolean/unset field-name val)
|
| 75 | (unless (eq? val unset-field)
|
| 76 | (serialize-field* field-name
|
| 77 | (if val "true" "false"))))
|
| 78 |
|
| 79 |
|
| 80 | |
| 81 | |
| 82 | (define (end-point? val)
|
| 83 | (match val
|
| 84 | ((? string?) #t)
|
| 85 | (((? string?) . (? integer?)) #t)
|
| 86 | (_ #f)))
|
| 87 |
|
| 88 | (define (serialize-end-point field-name val)
|
| 89 | (serialize-field* field-name
|
| 90 | (match val
|
| 91 | ((host . port)
|
| 92 | |
| 93 | (format #f "[~a]:~a" host port))
|
| 94 | (host
|
| 95 | (format #f "~a" host)))))
|
| 96 |
|
| 97 | (define (serialize-space-separated-string-list/unset field-name val)
|
| 98 | (unless (eq? val unset-field)
|
| 99 | (serialize-field* field-name (string-join val " "))))
|
| 100 |
|
| 101 | (define (space-separated-string-list? val)
|
| 102 | (and (list? val)
|
| 103 | (and-map (lambda (x)
|
| 104 | (and (string? x) (not (string-index x #\space))))
|
| 105 | val)))
|
| 106 |
|
| 107 | (define space-separated-string-list/unset?
|
| 108 | (predicate/unset space-separated-string-list?))
|
| 109 |
|
| 110 | (define comma-separated-integer-list/unset?
|
| 111 | (predicate/unset (lambda (val)
|
| 112 | (and (list? val)
|
| 113 | (and-map (lambda (x) (integer? x))
|
| 114 | val)))))
|
| 115 |
|
| 116 | (define (serialize-comma-separated-integer-list/unset field-name val)
|
| 117 | (unless (eq? val unset-field)
|
| 118 | (serialize-field* field-name
|
| 119 | (string-drop |
| 120 | (fold
|
| 121 | (lambda (i prev)
|
| 122 | (string-append prev "," (number->string i)))
|
| 123 | "" val) 1))))
|
| 124 |
|
| 125 | (define file-name? (predicate/unset
|
| 126 | (lambda (val)
|
| 127 | (string-prefix? "/" val))))
|
| 128 |
|
| 129 | (define (serialize-field field-name val)
|
| 130 | (format #t "~a ~a\n" (uglify-field-name field-name) val))
|
| 131 |
|
| 132 | (define (serialize-string field-name val)
|
| 133 | (serialize-field field-name val))
|
| 134 |
|
| 135 | (define (serialize-file-name field-name val)
|
| 136 | (unless (eq? val unset-field)
|
| 137 | (serialize-string field-name val)))
|
| 138 |
|
| 139 | (define (serialize-space-separated-string-list field-name val)
|
| 140 | (serialize-field field-name (string-join val " ")))
|
| 141 |
|
| 142 | (define (non-negative-integer? val)
|
| 143 | (and (exact-integer? val) (not (negative? val))))
|
| 144 |
|
| 145 | (define (serialize-non-negative-integer/unset field-name val)
|
| 146 | (unless (eq? val unset-field)
|
| 147 | (serialize-field* field-name val)))
|
| 148 |
|
| 149 | (define (free-form-fields? val)
|
| 150 | (match val
|
| 151 | (() #t)
|
| 152 | ((((? symbol?) . (? string)) . val) (free-form-fields? val))
|
| 153 | (_ #f)))
|
| 154 |
|
| 155 | (define (serialize-free-form-fields field-name val)
|
| 156 | (for-each (match-lambda ((k . v) (serialize-field* k v))) val))
|
| 157 |
|
| 158 | (define non-negative-integer/unset? (predicate/unset non-negative-integer?))
|
| 159 |
|
| 160 | (define (realm-list? val)
|
| 161 | (and (list? val)
|
| 162 | (and-map (lambda (x) (krb5-realm? x)) val)))
|
| 163 |
|
| 164 | (define (serialize-realm-list field-name val)
|
| 165 | (format #t "\n[~a]\n" field-name)
|
| 166 | (for-each (lambda (realm)
|
| 167 | (format #t "\n~a = {\n" (krb5-realm-name realm))
|
| 168 | (for-each (lambda (field)
|
| 169 | (unless (eq? 'name (configuration-field-name field))
|
| 170 | ((configuration-field-serializer field)
|
| 171 | (configuration-field-name field)
|
| 172 | ((configuration-field-getter field)
|
| 173 | realm)))) krb5-realm-fields)
|
| 174 |
|
| 175 | (format #t "}\n")) val))
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 | |
| 180 | (define-configuration krb5-realm
|
| 181 | (name
|
| 182 | (string/unset unset-field)
|
| 183 | "The name of the realm.")
|
| 184 |
|
| 185 | (kdc
|
| 186 | (end-point unset-field)
|
| 187 | "The host and port on which the realm's Key Distribution Server listens.")
|
| 188 |
|
| 189 | (admin-server
|
| 190 | (string/unset unset-field)
|
| 191 | "The Host running the administration server for the realm.")
|
| 192 |
|
| 193 | (master-kdc
|
| 194 | (string/unset unset-field)
|
| 195 | "If an attempt to get credentials fails because of an invalid password,
|
| 196 | the client software will attempt to contact the master KDC.")
|
| 197 |
|
| 198 | (kpasswd-server
|
| 199 | (string/unset unset-field)
|
| 200 | "The server where password changes are performed.")
|
| 201 |
|
| 202 | (auth-to-local
|
| 203 | (free-form-fields '())
|
| 204 | "Rules to map between principals and local users.")
|
| 205 |
|
| 206 | (auth-to-local-names
|
| 207 | (free-form-fields '())
|
| 208 | "Explicit mappings between principal names and local user names.")
|
| 209 |
|
| 210 | (http-anchors
|
| 211 | (free-form-fields '())
|
| 212 | "Useful only when http proxy is used to access KDC or KPASSWD.")
|
| 213 |
|
| 214 | |
| 215 | (default-domain
|
| 216 | (string/unset unset-field)
|
| 217 | "The domain used to expand host names when translating Kerberos 4 service
|
| 218 | principals to Kerberos 5 principals")
|
| 219 |
|
| 220 | (v4-instance-convert
|
| 221 | (free-form-fields '())
|
| 222 | "Exceptions to the default-domain mapping rule.")
|
| 223 |
|
| 224 | (v4-realm
|
| 225 | (string/unset unset-field)
|
| 226 | "Used when the V4 realm name and the V5 realm name are not the same, but
|
| 227 | still share the same principal names and passwords"))
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 | |
| 232 | (define-configuration krb5-configuration
|
| 233 | (allow-weak-crypto?
|
| 234 | (boolean/unset unset-field)
|
| 235 | "If true, permits access to services which only offer weak encryption.")
|
| 236 |
|
| 237 | (ap-req-checksum-type
|
| 238 | (non-negative-integer/unset unset-field)
|
| 239 | "The type of the AP-REQ checksum.")
|
| 240 |
|
| 241 | (canonicalize?
|
| 242 | (boolean/unset unset-field)
|
| 243 | "Should principals in initial ticket requests be canonicalized?")
|
| 244 |
|
| 245 | (ccache-type
|
| 246 | (non-negative-integer/unset unset-field)
|
| 247 | "The format of the credential cache type.")
|
| 248 |
|
| 249 | (clockskew
|
| 250 | (non-negative-integer/unset unset-field)
|
| 251 | "Maximum allowable clock skew in seconds (default 300).")
|
| 252 |
|
| 253 | (default-ccache-name
|
| 254 | (file-name unset-field)
|
| 255 | "The name of the default credential cache.")
|
| 256 |
|
| 257 | (default-client-keytab-name
|
| 258 | (file-name unset-field)
|
| 259 | "The name of the default keytab for client credentials.")
|
| 260 |
|
| 261 | (default-keytab-name
|
| 262 | (file-name unset-field)
|
| 263 | "The name of the default keytab file.")
|
| 264 |
|
| 265 | (default-realm
|
| 266 | (string/unset unset-field)
|
| 267 | "The realm to be accessed if not explicitly specified by clients.")
|
| 268 |
|
| 269 | (default-tgs-enctypes
|
| 270 | (free-form-fields '())
|
| 271 | "Session key encryption types when making TGS-REQ requests.")
|
| 272 |
|
| 273 | (default-tkt-enctypes
|
| 274 | (free-form-fields '())
|
| 275 | "Session key encryption types when making AS-REQ requests.")
|
| 276 |
|
| 277 | (dns-canonicalize-hostname?
|
| 278 | (boolean/unset unset-field)
|
| 279 | "Whether name lookups will be used to canonicalize host names for use in
|
| 280 | service principal names.")
|
| 281 |
|
| 282 | (dns-lookup-kdc?
|
| 283 | (boolean/unset unset-field)
|
| 284 | "Should DNS SRV records should be used to locate the KDCs and other servers
|
| 285 | not appearing in the realm specification")
|
| 286 |
|
| 287 | (err-fmt
|
| 288 | (string/unset unset-field)
|
| 289 | "Custom error message formatting. If not #f error messages will be formatted
|
| 290 | by substituting a normal error message for %M and an error code for %C in the
|
| 291 | value.")
|
| 292 |
|
| 293 | (forwardable?
|
| 294 | (boolean/unset unset-field)
|
| 295 | "Should initial tickets be forwardable by default?")
|
| 296 |
|
| 297 | (ignore-acceptor-hostname?
|
| 298 | (boolean/unset unset-field)
|
| 299 | "When accepting GSSAPI or krb5 security contexts for host-based service
|
| 300 | principals, ignore any hostname passed by the calling application, and allow
|
| 301 | clients to authenticate to any service principal in the keytab matching the
|
| 302 | service name and realm name.")
|
| 303 |
|
| 304 | (k5login-authoritative?
|
| 305 | (boolean/unset unset-field)
|
| 306 | "If this flag is true, principals must be listed in a local user's k5login
|
| 307 | file to be granted login access, if a ~/.k5login file exists.")
|
| 308 |
|
| 309 | (k5login-directory
|
| 310 | (string/unset unset-field)
|
| 311 | "If not #f, the library will look for a local user's @file{k5login} file
|
| 312 | within the named directory (instead of the user's home directory), with a
|
| 313 | file name corresponding to the local user name.")
|
| 314 |
|
| 315 | (kcm-mach-service
|
| 316 | (string/unset unset-field)
|
| 317 | "The name of the bootstrap service used to contact the KCM daemon for the
|
| 318 | KCM credential cache type.")
|
| 319 |
|
| 320 | (kcm-socket
|
| 321 | (file-name unset-field)
|
| 322 | "Path to the Unix domain socket used to access the KCM daemon for the KCM
|
| 323 | credential cache type.")
|
| 324 |
|
| 325 | (kdc-default-options
|
| 326 | (non-negative-integer/unset unset-field)
|
| 327 | "Default KDC options (logored for multiple values) when requesting initial
|
| 328 | tickets.")
|
| 329 |
|
| 330 | (kdc-timesync
|
| 331 | (non-negative-integer/unset unset-field)
|
| 332 | "Attempt to compensate for clock skew between the KDC and client.")
|
| 333 |
|
| 334 | (kdc-req-checksum-type
|
| 335 | (non-negative-integer/unset unset-field)
|
| 336 | "The type of checksum to use for the KDC requests. Relevant only for DES
|
| 337 | keys")
|
| 338 |
|
| 339 | (noaddresses?
|
| 340 | (boolean/unset unset-field)
|
| 341 | "If true, initial ticket requests will not be made with address restrictions.
|
| 342 | This enables their use across NATs.")
|
| 343 |
|
| 344 | (permitted-enctypes
|
| 345 | (space-separated-string-list/unset unset-field)
|
| 346 | "All encryption types that are permitted for use in session key encryption.")
|
| 347 |
|
| 348 | (plugin-base-dir
|
| 349 | (file-name unset-field)
|
| 350 | "The directory where krb5 plugins are located.")
|
| 351 |
|
| 352 | (preferred-preauth-types
|
| 353 | (comma-separated-integer-list/unset unset-field)
|
| 354 | "The preferred pre-authentication types which the client will attempt before
|
| 355 | others.")
|
| 356 |
|
| 357 | (proxiable?
|
| 358 | (boolean/unset unset-field)
|
| 359 | "Should initial tickets be proxiable by default?")
|
| 360 |
|
| 361 | (rdns?
|
| 362 | (boolean/unset unset-field)
|
| 363 | "Should reverse DNS lookup be used in addition to forward name lookup to
|
| 364 | canonicalize host names for use in service principal names.")
|
| 365 |
|
| 366 | (realm-try-domains
|
| 367 | (integer/unset unset-field)
|
| 368 | "Should a host's domain components should be used to determine the Kerberos
|
| 369 | realm of the host.")
|
| 370 |
|
| 371 | (renew-lifetime
|
| 372 | (non-negative-integer/unset unset-field)
|
| 373 | "The default renewable lifetime for initial ticket requests.")
|
| 374 |
|
| 375 | (safe-checksum-type
|
| 376 | (non-negative-integer/unset unset-field)
|
| 377 | "The type of checksum to use for the KRB-SAFE requests.")
|
| 378 |
|
| 379 | (ticket-lifetime
|
| 380 | (non-negative-integer/unset unset-field)
|
| 381 | "The default lifetime for initial ticket requests.")
|
| 382 |
|
| 383 | (udp-preference-limit
|
| 384 | (non-negative-integer/unset unset-field)
|
| 385 | "When sending messages to the KDC, the library will try using TCP
|
| 386 | before UDP if the size of the message greater than this limit.")
|
| 387 |
|
| 388 | (verify-ap-rereq-nofail?
|
| 389 | (boolean/unset unset-field)
|
| 390 | "If true, then attempts to verify initial credentials will fail if the client
|
| 391 | machine does not have a keytab.")
|
| 392 |
|
| 393 | (realms
|
| 394 | (realm-list '())
|
| 395 | "The list of realms which clients may access."))
|
| 396 |
|
| 397 |
|
| 398 | (define (krb5-configuration-file config)
|
| 399 | "Create a Kerberos 5 configuration file based on CONFIG"
|
| 400 | (mixed-text-file "krb5.conf"
|
| 401 | "[libdefaults]\n\n"
|
| 402 | (with-output-to-string
|
| 403 | (lambda ()
|
| 404 | (serialize-configuration config
|
| 405 | krb5-configuration-fields)))))
|
| 406 |
|
| 407 | (define (krb5-etc-service config)
|
| 408 | (list `("krb5.conf" ,(krb5-configuration-file config))))
|
| 409 |
|
| 410 |
|
| 411 | (define krb5-service-type
|
| 412 | (service-type (name 'krb5)
|
| 413 | (extensions
|
| 414 | (list (service-extension etc-service-type
|
| 415 | krb5-etc-service)))
|
| 416 | (description "Programs using a Kerberos client library
|
| 417 | normally expect a configuration file in @file{/etc/krb5.conf}. This service
|
| 418 | generates such a file. It does not cause any daemon to be started.")))
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 | (define-record-type* <pam-krb5-configuration>
|
| 423 | pam-krb5-configuration make-pam-krb5-configuration
|
| 424 | pam-krb5-configuration?
|
| 425 | (pam-krb5 pam-krb5-configuration-pam-krb5
|
| 426 | (default pam-krb5))
|
| 427 | (minimum-uid pam-krb5-configuration-minimum-uid
|
| 428 | (default 1000)))
|
| 429 |
|
| 430 | (define (pam-krb5-pam-service config)
|
| 431 | "Return a PAM service for Kerberos authentication."
|
| 432 | (pam-extension
|
| 433 | (transformer
|
| 434 | (lambda (pam)
|
| 435 | (define pam-krb5-module
|
| 436 | (file-append (pam-krb5-configuration-pam-krb5 config)
|
| 437 | "/lib/security/pam_krb5.so"))
|
| 438 |
|
| 439 | (let ((pam-krb5-sufficient
|
| 440 | (pam-entry
|
| 441 | (control "sufficient")
|
| 442 | (module pam-krb5-module)
|
| 443 | (arguments
|
| 444 | (list
|
| 445 | (format #f "minimum_uid=~a"
|
| 446 | (pam-krb5-configuration-minimum-uid config)))))))
|
| 447 | (pam-service
|
| 448 | (inherit pam)
|
| 449 | (auth (cons* pam-krb5-sufficient
|
| 450 | (pam-service-auth pam)))
|
| 451 | (session (cons* pam-krb5-sufficient
|
| 452 | (pam-service-session pam)))
|
| 453 | (account (cons* pam-krb5-sufficient
|
| 454 | (pam-service-account pam)))))))))
|
| 455 |
|
| 456 | (define (pam-krb5-pam-services config)
|
| 457 | (list (pam-krb5-pam-service config)))
|
| 458 |
|
| 459 | (define pam-krb5-service-type
|
| 460 | (service-type (name 'pam-krb5)
|
| 461 | (extensions
|
| 462 | (list
|
| 463 | (service-extension pam-root-service-type
|
| 464 | pam-krb5-pam-services)))
|
| 465 | (description "The @code{pam-krb5} service allows for login
|
| 466 | authentication and password management via Kerberos. You will need this
|
| 467 | service if you want PAM-enabled applications to authenticate users using
|
| 468 | Kerberos.")))
|