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

Add per-project hashing salt #371

Merged
merged 67 commits into from
Apr 15, 2024
Merged

Conversation

milanmlft
Copy link
Member

@milanmlft milanmlft commented Apr 11, 2024

Fixes #343

  • Use core.project_config.secrets.AzureKeyVault in hasher to set up Azure Key Vault connection
  • Hashing salts are now retrieved from the key vault, using the project-name as key
    • If no salt exists, a new one is created and stored in the key vault
  • Removed the old hasher key vault functionality
  • Salt generation is moved into the hashing functionality, so only hasher knows about it

To do

Avoids import errors in tests where the envvar is only set after the
imports.
Also remove `test_fetch_secret` as it's not testing our actual
`AzureKeyVault` class anyway
`Hasher` class sets up Azure Key vault connection and handles fetching
hashing keys and project salts.
This was a bit of a pain to monkeypatch in the tests, as the call to
`Hasher()` here kept trying to initiate an actual AzureKeyVault
instance, which would fail because the proper environment variables are
missing. Doing this at least allows us to monkeypatch the `Hasher` class
in the tests so that it uses a mock keyvault instance.
@milanmlft milanmlft requested a review from a team April 11, 2024 16:37
Copy link
Contributor

@stefpiatek stefpiatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking nice, but refactoring of keyvault won't actually cache sadly

pytest-pixl/src/pytest_pixl/plugin.py Outdated Show resolved Hide resolved
pytest-pixl/src/pytest_pixl/keyvault.py Outdated Show resolved Hide resolved
pixl_core/src/core/project_config/secrets.py Outdated Show resolved Hide resolved
pixl_core/src/core/project_config/secrets.py Outdated Show resolved Hide resolved
hasher/src/hasher/endpoints.py Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
hasher/src/hasher/hashing.py Outdated Show resolved Hide resolved
hasher/src/hasher/hashing.py Outdated Show resolved Hide resolved
Copy link
Contributor

@stefpiatek stefpiatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think some env changes are needed and a couple of questions about the public API

hasher/pyproject.toml Outdated Show resolved Hide resolved
hasher/pyproject.toml Outdated Show resolved Hide resolved
hasher/src/hasher/endpoints.py Outdated Show resolved Hide resolved
hasher/src/hasher/endpoints.py Show resolved Hide resolved
hasher/src/hasher/hashing.py Outdated Show resolved Hide resolved
hasher/src/hasher/main.py Show resolved Hide resolved
hasher/tests/conftest.py Outdated Show resolved Hide resolved
hasher/src/hasher/endpoints.py Outdated Show resolved Hide resolved
pixl_core/src/core/project_config/secrets.py Outdated Show resolved Hide resolved
test/.secrets.env.sample Show resolved Hide resolved
@milanmlft milanmlft enabled auto-merge (squash) April 15, 2024 16:23
@milanmlft milanmlft disabled auto-merge April 15, 2024 17:25
@milanmlft
Copy link
Member Author

Had to create a new secret in our dev Azure Keyvault under hasher--key to get system test passing. The Hasher API reads the secret configured with HASHER_API_AZ_KEY_VAULT_SECRET_NAME from the vault as key for the hashing. Added this to test/.env as well.

@milanmlft milanmlft enabled auto-merge (squash) April 15, 2024 17:47
@milanmlft milanmlft merged commit e1b9072 into main Apr 15, 2024
8 checks passed
@milanmlft milanmlft deleted the milanmlft/343-per-project-hashing-salt branch April 15, 2024 17:59
@peshence peshence mentioned this pull request Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Per project salt in PIXL hashing
2 participants