Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan refactor of secret and non-secret configuration data #1764

Closed
3 of 11 tasks
thekaveman opened this issue Oct 28, 2023 · 3 comments
Closed
3 of 11 tasks

Plan refactor of secret and non-secret configuration data #1764

thekaveman opened this issue Oct 28, 2023 · 3 comments
Assignees
Labels
back-end Django views, sessions, middleware, models, migrations etc. deliverable Work that ends with a non-code deliverable (e.g. Google doc) infrastructure Terraform, Azure, etc.

Comments

@thekaveman
Copy link
Member

thekaveman commented Oct 28, 2023

The existing Django models capture both secret configuration items and non-secret configuration items. The vast majority of fields are non-secret and do not require additional controls.

For the secret configuration, values are currently maintained in Azure Key Vault and read into a new app service environment each time the app restarts (e.g. with a new deploy, or if an engineer restarts the app manually during debugging).

We want to continue to maintain the majority non-secret configuration data simply and directly via Django models and stored in the Django database.

We need a plan for how to incorporate the secret values in an environment where we do not re-create the database each time the app restarts, and thus would not (necessarily) read from Key Vault at app startup time.

Acceptance Criteria

  • Secret configuration continues to be maintained in Azure Key Vault
  • Non-secret configuration is moved out of Azure Key Vault and is managed directly in the Django admin interface
  • Secret configuration is not visible within the Django admin interface (yet -- need roles/permissions etc.)
  • Engineers with appropriate access can update secret values in Azure Key Vault and apply the changes to the existing app deployment, perhaps requiring an app restart, but without requiring a new deployment

Additional context

Activities

Running list of activities related to this effort

Implementation plan

  • Implement a simple helper script in the spirit of this one in data-infra; use Azure's python libraries to read a value from a Key Vault by secret name. Ensure the Key Vault / environment (e.g. dev, test, prod) is not hardcoded; create a setting from an environment variable or similar.
  • Create a custom Django field type that inherits from models.TextField. The default field implementation stores the name of the secret. An instance method like get_secret_value() uses the helper script to get the value of the named secret on-demand.
  • Using the field mapping spreadsheet, update all secret fields to have this new field type. Update the field names to include _secret_name
  • Add new properties to each model that use the helper script above and the _secret_name field value to get the actual value of the secret. These properties should be named the same as the original (pre-refactor) secret field (e.g. without the _secret_name postfix)
@thekaveman thekaveman added back-end Django views, sessions, middleware, models, migrations etc. deliverable Work that ends with a non-code deliverable (e.g. Google doc) infrastructure Terraform, Azure, etc. labels Oct 28, 2023
@thekaveman thekaveman added this to the Admin tool: v1 milestone Oct 28, 2023
@thekaveman thekaveman moved this from Todo to Stretch in Digital Services Oct 31, 2023
@thekaveman
Copy link
Member Author

@thekaveman thekaveman moved this from Stretch to Todo in Digital Services Nov 13, 2023
@thekaveman thekaveman self-assigned this Nov 13, 2023
@thekaveman thekaveman moved this from Todo to In Progress in Digital Services Nov 13, 2023
@thekaveman thekaveman moved this from In Progress to Todo in Digital Services Nov 29, 2023
@thekaveman thekaveman moved this from Todo to Stretch in Digital Services Nov 29, 2023
@thekaveman
Copy link
Member Author

Could follow this pattern / helper function get_secret_by_name: https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-infra/calitp_data_infra/auth.py

@thekaveman thekaveman moved this from Stretch to Todo in Digital Services Jan 4, 2024
@thekaveman thekaveman moved this from Todo to In Progress in Digital Services Jan 9, 2024
@thekaveman thekaveman moved this from In Progress to In Review in Digital Services Jan 9, 2024
@thekaveman
Copy link
Member Author

We talked through this plan at a recent Dev Workshop, and made some adjustments based on the conversation. Those are reflected in the steps above.

@github-project-automation github-project-automation bot moved this from In Review to Done in Digital Services Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. deliverable Work that ends with a non-code deliverable (e.g. Google doc) infrastructure Terraform, Azure, etc.
Projects
Status: Done
Development

No branches or pull requests

1 participant