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

Store certificate and private key in encrypted CosmosDB database #2177

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

zkokelj
Copy link
Contributor

@zkokelj zkokelj commented Dec 3, 2024

Why this change is needed

We want to have static https certificate (using the same private key) even after restarts & certificate renewals etc.
Certificate and private key were previously stored in memory and in file on attached volume.
This is not ideal as it is stored unencrypted and in case of volume is deleted the private key and certificate are deleted.

Much better solution is to store both private key and certificate in encrypted CosmosDB.

What changes were made as part of this PR

  • implementation of autocert.Cache in which we store certificate and private key in cosmosDB and encrypt it.
  • using this approach only for CosmosDB (for other databases - sqlite, we still use file storage for certificate and private key)

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

lgtm.
minor comment

}

// dbKey generates a consistent key for CosmosDB storage
func (c *CertStorageCosmosDB) dbKey(key []byte) (string, azcosmos.PartitionKey) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to obfuscate the key. There will be only one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

First 2 are old (obfuscated keys) and the last two are keys after the change.

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

lgtm

@zkokelj zkokelj merged commit 28cc79e into main Dec 4, 2024
4 checks passed
@zkokelj zkokelj deleted the ziga/store_cert_priv_key_in_cosmosdb branch December 4, 2024 10:50
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.

2 participants