fix(deployments): persist non-SSH app credentials per group and teacher - #173
Merged
Dilmand merged 1 commit intoJun 29, 2026
Merged
Conversation
Previously, deploy_tasks built credentials_for_db with only SSH/Linux credentials — the per-group loop filtered on s['linux']['password'], and the teacher block only emitted an SSH admin entry. For templates whose app.yaml declares per_group credentials of any other type (postgres, pgadmin, web_url, ...), the resulting user_json had an empty 'instance.credentials' list and no 'applications' section, so DeploymentInstanceAccess rows were only ever written for the teacher's auto-generated SSH key. Students saw nothing in the lecturer UI either (no Gruppen tab) because no group_id-stamped rows existed. Now deploy_tasks discovers every non-bookkeeping key in generated['deployment_groups'][*] and generated['teacher'] (i.e. everything except username/email/group_name/group_index/course_group_id/ students/linux — linux is still handled via the dedicated SSH section) and emits one applications[] entry per credential type. Each entry carries group_id pulled from course_group_id for groups, and explicit None for the teacher's admin_credentials. SSH handling is unchanged. In the credential service, _extract_access_entries now reads group_id from each application credential and sets it explicitly to None for admin_credentials. Without this, even a populated applications[] would have written rows with group_id NULL and remained invisible to students. Verified against the ansible-postgres-group-db template (per_group: postgres + pgadmin, teacher: postgres + pgadmin, no linux): two groups × two cred types now yields four group-stamped DATABASE rows and two admin DATABASE rows, plus the existing SSH admin row.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Persist non-SSH credentials (postgres, pgadmin, web_url, …) into
deployment_instance_accessfor both groups and the teacher, so the lecturer UI's "Gruppen"-Tab is populated and students see their credentials via/api/v1/student/.Problem
For templates whose
app.yamldeclaresper_groupcredentials of any type other thanlinux(e.g.ansible-postgres-group-dbwithper_group: postgres + pgadmin), the lecturer UI showed only the teacher's auto-generated SSH row — no Gruppen-Tab, no per-group entries. Students saw nothing at all.Root cause in
src/tasks/deploy_tasks.py:253-279: the builder forcredentials_for_dbwas hardcoded to SSH/Linux:Templates without
per_group.linuxproduced an emptycredentials[].applications[]was never built. The teacher row only survived becausecredential_generator_serviceauto-generates alinuxblock for the teacher unconditionally (admin SSH key).A secondary issue:
_extract_access_entriesalready supporteduser_json["applications"][*], but didn't readgroup_idfrom those entries — so even ifapplications[]had been populated, every database row would have landed withgroup_id=NULLand been invisible to students.Changes
src/tasks/deploy_tasks.pyper_group.linuxstill don't get SSH access rows (correct — there's no Linux user on the VM to log into).applications[]by discovering every non-bookkeeping key ingenerated["deployment_groups"][*]andgenerated["teacher"]. Bookkeeping keys excluded:username,email,group_name,group_index,course_group_id,students,linux.applicationsentry per credential type.credentials[]carriesgroup_idper group (fromcourse_group_id);admin_credentialscarries the teacher's block (group_id forced toNonedownstream).src/services/deployment_credential_service.py_extract_access_entriesnow readsgroup_idfrom each per-group application credential and sets it explicitly toNoneforadmin_credentials— mirrors the existing SSH admin handling.Effect on existing templates
ansible-postgres-group-db(per_group: postgres + pgadmin)ansible-multiuser(per_group: linux)applications[]produced because the template has no non-linux per_group / teacher credsVerified
Tested locally against the staging
dilo-pgtemplate (ansible-postgres-group-db). After the fix, the lecturer UI shows the Gruppen-Tab with two groups, each with their postgres + pgadmin entries, and the Dozent-Tab shows the SSH admin row plus the teacher's postgres + pgadmin entries.Migration / backfill
Existing deployments are not retroactively backfilled — passwords aren't persisted before reaching this stage, so there's nothing to reconstruct them from. Deployments created before this fix will continue to show only the teacher SSH row. Re-deploy to get the full credential set.
Risks
credential_generator_service.py's output shape. If a future credential generator adds a new top-level bookkeeping key (e.g.metadata), it would leak intoapplications[]as a cred type. Mitigation: theNON_APP_KEYSset is one line to update.pgadmin_urlis read fromheat_outputsand applied globally per stack — unchanged behaviour, just exercised more often now.