Skip to content

Commit

Permalink
Fix token generator error handling and permissions and improve logging (
Browse files Browse the repository at this point in the history
#29)

* fix: improve error handling and logging for token generator

* fix: grant token generator permissions to patch secrets
  • Loading branch information
echozio authored May 28, 2024
1 parent 944f130 commit 58090a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scripts/token-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ def getSecret(fullname):
return None

def updateSecret(secret):
proc = subprocess.run(
subprocess.run(
[
"kubectl",
"apply",
"-f",
"-",
],
input=json.dumps(secret).encode(),
check=True,
)

def generateTokenSet(service, globalHashSecret):
Expand Down Expand Up @@ -103,6 +104,7 @@ def __main__():
try:
globalHashSecret = b64decode(secret["data"].get("globalHashSecret"))
except:
log("No global hash secret found, generating one...")
globalHashSecret = secrets.token_urlsafe(SECRET_LENGTH)
secret["data"]["globalHashSecret"] = b64encode(globalHashSecret)

Expand All @@ -114,6 +116,7 @@ def __main__():
b64decode(secret["data"].get(f"{service}AuthTokens")),
globalHashSecret
)
log(f"Token for {service} is valid.")
except:
log(f"Generating token for {service}...")
secret["data"].update(generateTokenSet(service, globalHashSecret))
Expand Down
2 changes: 1 addition & 1 deletion templates/token-generator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
verbs: ["create", "patch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
Expand Down

0 comments on commit 58090a8

Please sign in to comment.