Skip to content

Commit 62a40f5

Browse files
Michael Vasseurvmcj
authored andcommitted
Add script to auto-generate the xkcd passwords
This simplifies setting up the contests and makes that we set reasonable strength passwords by default. In case you make multiple groups (for example WF4{47}) we can work from the templates set in git.
1 parent 56371c4 commit 62a40f5

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

provision-contest/ansible/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ to prevent duplication.
2424
Global and group variables are stored under `group_vars`. The file
2525
`group_vars/all/secret.yml.example` should be copied to
2626
`group_vars/all/secret.yml` and then all variables should be set
27-
and/or modified as required.
27+
and/or modified as required. The script `generate_passwords.py` can be used
28+
to prefill some of those passwords with a xkcd style password. In `secret.yml.example`
29+
the passwords can be listed as either `{some-password}` or `some-password` the `{}` is *not*
30+
required but only used as anchor for the script, so adding the `{}` would make it part of the
31+
password.
2832

2933
There are a few places where additional files should/can be added:
3034
* SSH public/private keys under `roles/ssh/files/`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
# Script based on: https://pypi.org/project/xkcdpass/
4+
from xkcdpass import xkcd_password as xp
5+
import re, os
6+
7+
words = xp.generate_wordlist(wordfile=xp.locate_wordfile(), min_length=3, max_length=8)
8+
9+
for root,_,files in os.walk('group_vars'):
10+
out = ''
11+
if '/' not in root:
12+
continue
13+
if 'secret.yml.example' not in files:
14+
continue
15+
if os.path.isfile(os.path.join(root, 'secret.yml')):
16+
print("Secret file exists already, exiting.")
17+
exit(-1)
18+
with open(os.path.join(root, 'secret.yml.example'), 'r') as fi:
19+
for line in fi:
20+
if '{' in line:
21+
parms = str(re.search('{.*}', line).group())[1:-1]
22+
if '-' in parms:
23+
if 'strong' in parms:
24+
vls = {parms: xp.generate_xkcdpassword(words, numwords=5, delimiter='-')}
25+
else:
26+
vls = {parms: xp.generate_xkcdpassword(words, numwords=3, delimiter='-')}
27+
out += line.format(**vls)
28+
else:
29+
out += line
30+
with open(os.path.join(root, 'secret.yml'), 'w') as fo:
31+
fo.write(out)

provision-contest/ansible/group_vars/all/secret.yml.example

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1+
# Templated passwords as `{some-strong-password}` are written to make sure our
2+
# script detects those, if you manually change those the `{}` are not required and
3+
# would become part of the password.
4+
# Adding `strong` in the template will create longer passwords and is used for the
5+
# passwords which almost never need to be manually typed.
6+
17
# Password for the MySQL replication user.
28
# Set this to enable master-master replication between two domservers.
3-
#REPLICATION_PASSWORD: some-replication-password
9+
#REPLICATION_PASSWORD: {some-strong-replication-password}
410

511
# Database user password.
6-
DB_PASSWORD: some-database-password
12+
DB_PASSWORD: {some-strong-database-password}
713

814
# Credentials for the judgehost.
915
JUDGEHOST_USER: judgehost
10-
JUDGEHOST_PASSWORD: some-judgehost-password
16+
JUDGEHOST_PASSWORD: {some-strong-judgehost-password}
1117

1218
# Username and password to be used in .netrc files on admin machines
1319
ADMIN_USER: admin
14-
ADMIN_PASSWORD: some-admin-password
20+
ADMIN_PASSWORD: {some-admin-password}
1521

1622
# Password for domjudge shell user
1723
# Set this to enable a password on the 'domjudge' shell accounts
1824
# created on the domserver and judgehosts.
19-
#DJ_SHELL_USER_PW: some-hashed-password
25+
#DJ_SHELL_USER_PW: {some-hashed-password}
2026

2127
# Accounts to create when setting up the CDS
2228
CDS_ACCOUNTS:
2329
- username: admin
24-
password: adm1n
30+
password: {some-adm1n-password}
2531
type: admin
2632
- username: presAdmin
27-
password: padm1n
33+
password: {some-presentation-adm1n-password}
2834
type: admin
2935
- username: blue
3036
password: blu3
@@ -36,7 +42,7 @@ CDS_ACCOUNTS:
3642
password: publ1c
3743
type: public
3844
- username: presentation
39-
password: presentat1on
45+
password: {some-public-presentation-password}
4046
type: public
4147
- username: myicpc
4248
password: my1cpc

0 commit comments

Comments
 (0)