1
0
Fork 0
forked from infra/keys

Compare commits

...

9 commits

Author SHA1 Message Date
ef2e22d65a Merge pull request 'script bugfixes' (#6) from script-fixes into main
Reviewed-on: infra/keys#6
2025-02-04 23:38:51 +00:00
d830965d7a
unfuck ref resolution too 2025-02-05 00:37:13 +01:00
3b5981d9cd
script bugfixes
- author casing
- trailing newline to make git recognize keys correctly
2025-02-05 00:10:36 +01:00
b3a5c69e04 Merge pull request 'add keys for lilian' (#5) from lilian into main
Reviewed-on: infra/keys#5
Reviewed-by: kleines Filmröllchen <filmroellchen@noreply.localhost>
2025-02-01 18:17:16 +00:00
f1f976a901
add keys for lilian 2025-01-29 22:11:18 +01:00
2ce94e816f Merge pull request 'Add keys for Sid' (#4) from autinerd/keys:keys-autinerd into main
Reviewed-on: infra/keys#4
Reviewed-by: kleines Filmröllchen <filmroellchen@noreply.localhost>
2025-01-29 19:51:24 +00:00
aee0400ff1 Merge pull request 'add keys for denny' (#3) from denny into main
Reviewed-on: infra/keys#3
Reviewed-by: kleines Filmröllchen <filmroellchen@noreply.localhost>
2025-01-29 19:50:22 +00:00
38363c8654
Add keys for Sid 2025-01-29 20:28:32 +01:00
35f82bb0ef
add keys for denny 2025-01-29 18:05:02 +01:00
10 changed files with 33 additions and 5 deletions

1
autinerd/keys Normal file
View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDJIN3GrRR5suQHnWBL7b/W4gu2CoZZK+eXOsicnHct3 sidney

2
autinerd/meta.toml Normal file
View file

@ -0,0 +1,2 @@
name = "autinerd"
email = "autinerd@noreply.localhost"

1
autinerd/wireguard Normal file
View file

@ -0,0 +1 @@
fugelNyT7VVriZgB6gwebHH/JfsZGQ8G34xjb6uVY0k=

1
denny/keys Normal file
View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGo9RUJ7MiKAsWdBKaYqUFYZAFl6qsOlSv+GEN5Z5Bdu denny

3
denny/meta.toml Normal file
View file

@ -0,0 +1,3 @@
name = "denny"
email = "denny@dennybertus.de"

1
denny/wireguard Normal file
View file

@ -0,0 +1 @@
oMTiAkSRrvqxLuy59YzjXPgy8R5CuGvwDW6/vorOHgk=

2
lilian/keys Normal file
View file

@ -0,0 +1,2 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINTt9fIKrXhfUYCKdpkI8etdvNgn8jubA2YxvdFj4Rn5 lilian@metis
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFc/fKL52XHMx2oM9YE9o20zQ/Y+JAwx+YSUPdT+Y7Vf lilian@cordelia

2
lilian/meta.toml Normal file
View file

@ -0,0 +1,2 @@
name = "lilian"
email = "lilian.no-reply@chaostreff-backnang.de"

1
lilian/wireguard Normal file
View file

@ -0,0 +1 @@
PSnR3Z+O9ChkFsQSsFzYk23fnyeCaqzF2cH+4MnK5xI=

View file

@ -28,14 +28,15 @@ def collect_user_dirs():
def last_commit_for(dir: Path, ref: git.Reference):
"""Returns the Git commit signature for the last commit on this path."""
last_commit_hash = str(ref.repo.git.rev_list("--max-count=1", action_ref, dir))
last_commit_hash = str(ref.repo.git.rev_list("--max-count=1", ref, dir))
return ref.repo.commit(last_commit_hash)
def keylist_to_principals(keyfile_text: str, email: str) -> str:
# trailing newline, otherwise git may get confused and reject the key
return "\n".join(
f"{email} {public_key}" for public_key in keyfile_text.splitlines()
)
) + "\n"
def get_forgejo_keys(username: str) -> str:
@ -53,7 +54,8 @@ def verify_dir(dir: Path, ref: git.Reference):
raise Exception("Missing keyfile")
commit = last_commit_for(dir, ref)
log.debug(f"Found last commit: {commit.name_rev}")
if commit.author.name != username:
# ignore author casing
if commit.author.name.lower() != username.lower():
raise Exception(
f"Commit author {commit.author.name} is not the owner of this directory."
)
@ -80,9 +82,10 @@ def verify_dir(dir: Path, ref: git.Reference):
config.set_value("gpg.ssh", "allowedSignersFile", temp_keyfile.name)
temp_keyfile_contents = keylist_to_principals(remote_keys, email)
log.debug(f"temp keyfile:\n{temp_keyfile_contents}")
temp_keyfile.write(temp_keyfile_contents)
temp_keyfile.flush()
log.debug(f"temp keyfile:\n{Path(temp_keyfile.name).read_text()}")
# Check whether one of the user keys signed this commit.
# throws an exception automatically if verification fails, nothing else to do
ref.repo.git.verify_commit("--raw", commit.hexsha)
@ -98,7 +101,18 @@ def verify_dir(dir: Path, ref: git.Reference):
def current_ref(repo: git.Repo) -> git.Reference:
for ref in repo.references:
log.debug(f"{repo.references}")
# some of this logic stolen from https://code.forgejo.org/actions/checkout/src/branch/main/src/ref-helper.ts - the ref names github provides are beyond fucked
global action_ref
if (action_ref.startswith('refs/heads/')):
branch = action_ref.removeprefix('refs/heads/')
action_ref = branch
# refs/pull/
elif (action_ref.startswith('refs/pull/')):
branch = action_ref.removeprefix('refs/pull/')
action_ref = f'refs/remotes/pull/{branch}'
for ref in repo.refs:
if ref.name == action_ref or ref.path == action_ref:
return ref
raise Exception(f"No ref named {action_ref} found")