Skip to content

Commit 6b2b6b2

Browse files
committed
Refactor to support pushes to Wizard. This invalidates the old 'common' cache.
Legacy-ID: 2297
1 parent 7ac2508 commit 6b2b6b2

File tree

1 file changed

+90
-42
lines changed

1 file changed

+90
-42
lines changed

host/credit-card/host.py

+90-42
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,40 @@
1010

1111
HOST = socket.gethostname()
1212

13-
# XXX test server and wizard server
14-
15-
# UIDs (sketchy):
16-
# signup 102
17-
# fedora-ds 103 (sketchy, not true for b-b)
18-
# logview 501 (really sketchy, since it's in the dynamic range)
19-
20-
# Works for passwd and group, but be careful! They're different things!
21-
def lookup(filename):
22-
# Super-safe to assume and volume IDs (expensive to check)
23-
r = {
24-
'root': 0,
25-
'sql': 537704221,
26-
}
27-
with open(filename, 'rb') as f:
28-
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
29-
for row in reader:
30-
r[row[0]] = int(row[2])
31-
return r
32-
33-
# Format here assumes that we always chmod $USER:$USER ...
13+
PROD_GUESTS = frozenset([
14+
'bees-knees',
15+
'cats-whiskers',
16+
'busy-beaver',
17+
'pancake-bunny',
18+
'whole-enchilada',
19+
'real-mccoy',
20+
'old-faithful',
21+
'better-mousetrap',
22+
'shining-armor',
23+
'golden-egg',
24+
'miracle-cure',
25+
'lucky-star',
26+
])
27+
WIZARD_GUESTS = frozenset([
28+
'not-backward',
29+
])
30+
31+
COMMON_CREDS = {}
32+
33+
# Format here assumes that we always chmod $USER:$USER,
3434
# but note the latter refers to group...
35-
COMMON_CREDS = [
35+
#
36+
# Important: no leading slashes!
37+
COMMON_CREDS['all'] = [
3638
('root', 0o600, 'root/.bashrc'),
3739
('root', 0o600, 'root/.screenrc'),
3840
('root', 0o600, 'root/.ssh/authorized_keys'),
3941
('root', 0o600, 'root/.ssh/authorized_keys2'),
4042
('root', 0o600, 'root/.vimrc'),
4143
('root', 0o600, 'root/.k5login'),
42-
# punted /root/.ssh/known_hosts
43-
44-
# XXX user must be created in Kickstart
45-
('logview', 0o600, 'home/logview/.k5login'),
4644
]
4745

48-
COMMON_PROD_CREDS = [ # important: no leading slashes!
46+
COMMON_CREDS['prod'] = [
4947
('root', 0o600, 'root/.ldapvirc'),
5048
('root', 0o600, 'etc/ssh/ssh_host_dsa_key'),
5149
('root', 0o600, 'etc/ssh/ssh_host_key'),
@@ -62,14 +60,48 @@ def lookup(filename):
6260
('sql', 0o600, 'etc/sql-mit-edu.cfg.php'), # technically doesn't have to be secret anymore
6361
('sql', 0o600, 'etc/sql-password'),
6462
('signup', 0o600, 'etc/signup-ldap-pw'),
63+
('logview', 0o600, 'home/logview/.k5login'), # XXX user must be created in Kickstart
6564
]
6665

67-
MACHINE_PROD_CREDS = [
68-
# XXX NEED TO CHECK THAT THESE ARE SENSIBLE
66+
# note that these are duplicates with 'prod', but the difference
67+
# is that the files DIFFER between wizard and prod
68+
COMMON_CREDS['wizard'] = [
69+
('root', 0o600, 'etc/ssh/ssh_host_dsa_key'),
70+
('root', 0o600, 'etc/ssh/ssh_host_key'),
71+
('root', 0o600, 'etc/ssh/ssh_host_rsa_key'),
72+
('afsagent', 0o600, 'etc/daemon.keytab'),
73+
74+
('root', 0o644, 'etc/ssh/ssh_host_dsa_key.pub'),
75+
('root', 0o644, 'etc/ssh/ssh_host_key.pub'),
76+
('root', 0o644, 'etc/ssh/ssh_host_rsa_key.pub'),
77+
]
78+
79+
MACHINE_CREDS = {}
80+
81+
MACHINE_CREDS['all'] = [
82+
# XXX NEED TO CHECK THAT THE CONTENTS ARE SENSIBLE
6983
('root', 0o600, 'etc/krb5.keytab'),
70-
('fedora-ds', 0o600, 'etc/dirsrv/keytab')
7184
]
7285

86+
MACHINE_CREDS['prod'] = [
87+
('fedora-ds', 0o600, 'etc/dirsrv/keytab'),
88+
]
89+
90+
MACHINE_CREDS['wizard'] = []
91+
92+
# Works for passwd and group, but be careful! They're different things!
93+
def lookup(filename):
94+
# Super-safe to assume and volume IDs (expensive to check)
95+
r = {
96+
'root': 0,
97+
'sql': 537704221,
98+
}
99+
with open(filename, 'rb') as f:
100+
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
101+
for row in reader:
102+
r[row[0]] = int(row[2])
103+
return r
104+
73105
def drop_caches():
74106
with open("/proc/sys/vm/drop_caches", 'w') as f:
75107
f.write("1")
@@ -129,29 +161,37 @@ def __exit__(self, _type, _value, _traceback):
129161
drop_caches()
130162

131163
def main():
132-
usage = """usage: %prog [push|pull|pull-common] GUEST"""
164+
usage = """usage: %prog [push|pull] [common|machine] GUEST"""
133165

134166
parser = optparse.OptionParser(usage)
135167
# ext3 will probably supported for a while yet and a pretty
136168
# reasonable thing to always try
137169
parser.add_option('-t', '--types', dest="types", default="ext4,ext3",
138-
help="filesystem type(s)")
170+
help="filesystem type(s)") # same arg as 'mount'
139171
parser.add_option('--creds-dir', dest="creds_dir", default="/root/creds",
140172
help="directory to store/fetch credentials in")
141173
options, args = parser.parse_args()
142174

143175
if not os.path.isdir(options.creds_dir):
144-
raise Exception("/root/creds does not exist") # XXX STRING
176+
raise Exception("%s does not exist" % options.creds_dir)
145177
# XXX check owned by root and appropriately chmodded
146178

147179
os.umask(0o077) # overly restrictive
148180

149-
if len(args) != 2:
181+
if len(args) != 3:
150182
parser.print_help()
151183
raise Exception("Wrong number of arguments")
152184

153185
command = args[0]
154-
guest = args[1]
186+
files = args[1]
187+
guest = args[2]
188+
189+
if guest in PROD_GUESTS:
190+
mode = 'prod'
191+
elif guest in WIZARD_GUESTS:
192+
mode = 'wizard'
193+
else:
194+
raise Exception("Unrecognized guest %s" % guest)
155195

156196
with WithMount(guest, options.types) as tmp_mount:
157197
uid_lookup = lookup("%s/etc/passwd" % tmp_mount)
@@ -177,15 +217,23 @@ def pull_files(files, type):
177217
# error if doesn't exist
178218
shutil.copyfile("%s/%s" % (tmp_mount, f), dest)
179219

220+
# XXX ideally we should check these *before* we mount, but Python
221+
# makes that pretty annoying to do
180222
if command == "push":
181-
push_files(COMMON_CREDS, 'common')
182-
push_files(COMMON_PROD_CREDS, 'common')
183-
push_files(MACHINE_PROD_CREDS, 'machine/%s' % guest)
223+
run = push_files
184224
elif command == "pull":
185-
pull_files(MACHINE_PROD_CREDS, 'machine/%s' % guest)
186-
elif command == "pull-common":
187-
pull_files(COMMON_CREDS, 'common')
188-
pull_files(COMMON_PROD_CREDS, 'common')
225+
run = pull_files
226+
else:
227+
raise Exception("Unknown command %s, valid values are 'push' and 'pull'" % command)
228+
229+
if files == 'common':
230+
run(COMMON_CREDS['all'], 'all')
231+
run(COMMON_CREDS[mode], mode)
232+
elif files == 'machine':
233+
run(MACHINE_CREDS['all'], 'machine/%s' % guest)
234+
run(MACHINE_CREDS[mode], 'machine/%s' % guest)
235+
else:
236+
raise Exception("Unknown file set %s, valid values are 'common' and 'machine'" % files)
189237

190238
if __name__ == "__main__":
191239
main()

0 commit comments

Comments
 (0)