[2565] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | """Re-generate the remctl configuration for build submissions. |
---|
| 4 | |
---|
| 5 | This script generates the remctl ACL and configuration for each build |
---|
[2579] | 6 | pocket defined in the configuration. It also updates the .k5login for |
---|
| 7 | the git user that developers can push through. |
---|
[2565] | 8 | """ |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | import os |
---|
| 12 | import tempfile |
---|
| 13 | |
---|
| 14 | from invirt.authz import mech as authz |
---|
[2584] | 15 | from invirt import builder |
---|
[2565] | 16 | from invirt.config import structs as config |
---|
| 17 | |
---|
| 18 | |
---|
[2566] | 19 | def userToPrinc(user): |
---|
| 20 | """Convert an AFS principal to a Kerberos v5 principal.""" |
---|
| 21 | if '@' in user: |
---|
| 22 | (princ, realm) = user.split('@') |
---|
| 23 | else: |
---|
| 24 | princ = user |
---|
| 25 | realm = config.kerberos.realm |
---|
| 26 | |
---|
| 27 | return princ.replace('.', '/') + '@' + realm |
---|
| 28 | |
---|
| 29 | |
---|
[2565] | 30 | def main(): |
---|
[2579] | 31 | all_devs = set() |
---|
| 32 | |
---|
[2565] | 33 | # Python could really use a file-like object that gets written to |
---|
| 34 | # a temporary path and moved to its final resting place on |
---|
| 35 | # .close(). Oh well. |
---|
[2567] | 36 | conf_fd, conf_name = tempfile.mkstemp() |
---|
[2569] | 37 | conf = os.fdopen(conf_fd, 'r+') |
---|
[2565] | 38 | build_handler = '/usr/sbin/invirt-submit-build' |
---|
| 39 | |
---|
[2593] | 40 | for pocket in config.build.pockets: |
---|
| 41 | acl = authz.expandAdmin(getattr(config.build.pockets, pocket).acl, None) |
---|
[2565] | 42 | |
---|
[2567] | 43 | acl_fd, acl_name = tempfile.mkstemp() |
---|
[2569] | 44 | acl_fd = os.fdopen(acl_fd, 'r+') |
---|
[2568] | 45 | print >>acl_fd, '\n'.join(userToPrinc(a) for a in acl) |
---|
[2565] | 46 | |
---|
[2579] | 47 | all_devs.update(set(userToPrinc(a) for a in acl)) |
---|
| 48 | |
---|
[2565] | 49 | acl_path = os.path.join('/etc/remctl/acl/build-%s' % pocket) |
---|
| 50 | |
---|
[2567] | 51 | os.rename(acl_name, acl_path) |
---|
[2565] | 52 | print >>conf, 'build %s %s %s' % (pocket, build_handler, acl_path) |
---|
| 53 | |
---|
[2567] | 54 | os.rename(conf_name, '/etc/remctl/conf.d/build') |
---|
[2565] | 55 | |
---|
[2579] | 56 | k5login_fd, k5login_name = tempfile.mkstemp() |
---|
| 57 | k5login = os.fdopen(k5login_fd, 'r+') |
---|
| 58 | print >>k5login, '\n'.join(all_devs) |
---|
[2565] | 59 | |
---|
[2584] | 60 | os.rename(k5login_name, os.path.join(builder._REPO_DIR, '.k5login')) |
---|
[2579] | 61 | |
---|
[2584] | 62 | |
---|
[2565] | 63 | if __name__ == '__main__': |
---|
| 64 | main() |
---|