DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Encrypt and Check Your Secrets Into Git

Encrypt and Check Your Secrets Into Git

What do you do with your secrets and tokens for a given project and how do you store them and distribute them? In this post, we look at one developer's solution.

David Karapetyan user avatar by
David Karapetyan
·
Apr. 24, 17 · Analysis
Like (0)
Save
Tweet
Share
2.33K Views

Join the DZone community and get the full member experience.

Join For Free

When it comes to managing secret tokens, whatever you do, someone will come out and say you’re doing it wrong and propose an alternate solution that on the surface seems to be better, but upon closer scrutiny is susceptible to the same attack vectors. The secure solution is always some kind of custom solution for storing secrets that provides an audit trail. The audit trail means whenever a secret is accessed you have a log entry of it somewhere. Which is nice because when stuff leaks you can, in theory, trace it back to some specific person. Unless that person was hacked and they were used as a patsy. So today, let’s compare storing encrypted secrets in git or some custom solution that is not git.

We have to make some assumptions here to see if git is any better or worse. We assume everything is encrypted at rest with some secret key that is not available to the attacker. The essential difference between git and the non-git solution is the audit trail and access to historical ciphertexts for a given plaintext. In git, the attacker has access to the history of the ciphertexts starting at some point in time. In the non-git case, they only ever get to see a snapshot of the ciphertext. Although I’m sure some custom solutions do offer versioning which makes them equivalent to git.

So what happens when the plaintext is leaked in the git case? Well, we have to cut off access and rotate the plaintext secret. This invalidates the plaintext that was leaked and we are good to go. It doesn’t matter if the attacker had the entire history of the ciphertexts for the plaintext because only the latest one has any meaning.

What happens when the plaintext leaks in the non-git case? We cut off access and rotate the plaintext secret. The attacker now holds a secret token that is meaningless. Same as in the git case.

Now let’s assume the attacker gets our secret key and runs away with the crown jewels. What happens in the git and non-git case now?

In the git case, the attacker has the history of the ciphertexts and the secret key so they decrypt the ciphertexts and keep the latest version of the plaintext. So the only thing we can do is rotate the private key and the plaintext and check things into git again. The fact that the attacker still has the historical data no longer matters because all the old keys are meaningless.

In the non-git case, the attacker decrypts the snapshot of the ciphertext they currently have. In this case, again we have to rotate everything. This invalidates whatever the attacker has because the old keys are gone.

So what did we do differently in the git vs non-git case? Nothing. If we leak the plaintext then we rotate it. If we leak the secret key then we have to rotate everything. The response is the same whether you store your secret tokens in git or somewhere else.

Now an argument could be made about access control, but again, when we do the analysis, the solutions in git and non-git case are equivalent. gpg allows encrypting the same secret with multiple keys so that multiple recipients can decrypt it. So the question is, how do you go about revoking access?

In the git case, you rotate and re-encrypt the plaintexts with one less recipient. If you don’t rotate then it is meaningless to re-encrypt things, because, assuming the attacker had access at some point, they still have the same key.

In the non-git case, you revoke the attacker’s access. Again if you don’t rotate the keys the attacker had access to, then revoking their access is meaningless. They still have the key so you have to rotate the key after revoking access.

So what did we do differently in the git vs non-git case for access management? Nothing. We had to revoke access and rotate the secret token.

So save yourself the headache of the custom solution and just set up gpg and check in your encrypted secret tokens into git. There are several solutions out there for doing that. A good one I saw recently was blackbox.

Git

Published at DZone with permission of David Karapetyan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Explainer: Building High Performing Data Product Platform
  • Simulating and Troubleshooting StackOverflowError in Kotlin
  • NEXT.JS 13: Be Dynamic Without Limits
  • Handling Automatic ID Generation in PostgreSQL With Node.js and Sequelize

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: