Skip to content

feat: decrypt env vars in CTRL workflow before passing to Krane#4453

Merged
chronark merged 15 commits intomainfrom
feat/env-vars-ctrl-decryption
Dec 9, 2025
Merged

feat: decrypt env vars in CTRL workflow before passing to Krane#4453
chronark merged 15 commits intomainfrom
feat/env-vars-ctrl-decryption

Conversation

@Flo4604
Copy link
Member

@Flo4604 Flo4604 commented Dec 2, 2025

What does this PR do?

This stores the current environment variables of the environment we are deploying into a snapshot for our deployments table.

It also decrypts the variables when deploying and passes them into krane.
(doesnt compile because protobuf is changed in the next pr.)

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

Test in the last branch of the stack.

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@changeset-bot
Copy link

changeset-bot bot commented Dec 2, 2025

⚠️ No Changeset found

Latest commit: a75e1b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Dec 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
dashboard Error Error Dec 9, 2025 4:16pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
engineering Ignored Ignored Preview Dec 9, 2025 4:16pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds vault integration for managing deployment secrets. It wires the vault service into deployment and certificate services, captures deployment environment variables as encrypted secrets during creation, and decrypts them during execution using the vault service.

Changes

Cohort / File(s) Summary
Vault service initialization & wiring
go/apps/ctrl/run.go, go/apps/ctrl/workflows/deploy/service.go
Added vault service field to Workflow struct and wired vaultSvc into DeploymentServiceServer and CertificateServiceServer configurations.
Secrets capture & encryption
go/apps/ctrl/services/deployment/create_deployment.go
Implemented environment variable capture, SecretsConfig map construction, protobuf JSON marshaling, and storage of encrypted secrets blob with deployment insertion.
Secrets decryption & integration
go/apps/ctrl/workflows/deploy/deploy_handler.go
Added SecretsConfig unmarshaling, Vault-based secret decryption per workspace, and integration of decrypted environment variables into Krane deployment requests.

Sequence Diagram

sequenceDiagram
    participant Client
    participant DeploymentService as Deployment Service
    participant Vault
    participant Database
    participant DeployHandler as Deploy Handler
    participant Krane

    Client->>DeploymentService: Create deployment (env vars)
    activate DeploymentService
    DeploymentService->>DeploymentService: Build SecretsConfig map
    DeploymentService->>DeploymentService: Marshal to protobuf JSON
    DeploymentService->>Database: Insert deployment + SecretsConfig blob
    Database-->>DeploymentService: Deployment created
    deactivate DeploymentService
    
    rect rgba(100, 200, 150, 0.3)
    Note over DeployHandler,Krane: Deployment execution phase
    DeployHandler->>Database: Fetch deployment + SecretsConfig
    Database-->>DeployHandler: Deployment with encrypted secrets
    DeployHandler->>DeployHandler: Unmarshal SecretsConfig (protobuf)
    
    loop For each secret
        DeployHandler->>Vault: Decrypt secret (workspace keyring)
        Vault-->>DeployHandler: Decrypted value
    end
    
    DeployHandler->>Krane: Create deployment (EnvVars map)
    Krane-->>DeployHandler: Deployment request processed
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • go/apps/ctrl/services/deployment/create_deployment.go: Verify environment variable capture, protobuf JSON marshaling correctness, and error handling for fetch/marshal operations
  • go/apps/ctrl/workflows/deploy/deploy_handler.go: Review decryption logic, error propagation during unmarshal/decrypt, and null-safety checks for vault service
  • go/apps/ctrl/run.go and go/apps/ctrl/workflows/deploy/service.go: Confirm vault service wiring is consistent across all service configurations
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/env-vars-ctrl-decryption

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b358cbf and a75e1b4.

📒 Files selected for processing (4)
  • go/apps/ctrl/run.go (1 hunks)
  • go/apps/ctrl/services/deployment/create_deployment.go (3 hunks)
  • go/apps/ctrl/workflows/deploy/deploy_handler.go (3 hunks)
  • go/apps/ctrl/workflows/deploy/service.go (4 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel vercel bot temporarily deployed to Preview – engineering December 2, 2025 13:41 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 2, 2025 13:44 Inactive
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from 66f4d6a to b656788 Compare December 2, 2025 13:57
@vercel vercel bot temporarily deployed to Preview – engineering December 2, 2025 13:57 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 2, 2025 13:58 Inactive
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from b656788 to ddcd457 Compare December 2, 2025 14:06
@vercel vercel bot temporarily deployed to Preview – engineering December 2, 2025 14:06 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 2, 2025 14:09 Inactive
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from ddcd457 to b3eac6f Compare December 2, 2025 14:13
@Flo4604 Flo4604 force-pushed the feat/env-vars-dashboard-ui branch from dff1739 to 326ba6e Compare December 2, 2025 14:13
@vercel vercel bot temporarily deployed to Preview – engineering December 2, 2025 14:14 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 2, 2025 14:17 Inactive
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from b3eac6f to df024e6 Compare December 2, 2025 14:42
@Flo4604 Flo4604 force-pushed the feat/env-vars-dashboard-ui branch from 326ba6e to a049700 Compare December 2, 2025 14:42
@vercel vercel bot temporarily deployed to Preview – engineering December 2, 2025 14:43 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 2, 2025 14:45 Inactive
@Flo4604 Flo4604 marked this pull request as ready for review December 2, 2025 14:55
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from df024e6 to 6c33142 Compare December 2, 2025 15:47
@vercel vercel bot temporarily deployed to Preview – engineering December 4, 2025 09:52 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 4, 2025 09:52 Inactive
@Flo4604 Flo4604 force-pushed the feat/env-vars-ctrl-decryption branch from 974e517 to 9adddc0 Compare December 4, 2025 17:36
@Flo4604 Flo4604 force-pushed the feat/env-vars-dashboard-ui branch from 203e039 to 8d1c219 Compare December 4, 2025 17:36
@vercel vercel bot temporarily deployed to Preview – engineering December 4, 2025 17:37 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard December 4, 2025 17:40 Inactive
@Flo4604 Flo4604 mentioned this pull request Dec 4, 2025
19 tasks
Base automatically changed from feat/env-vars-dashboard-ui to main December 9, 2025 16:13
@chronark chronark merged commit 5f2bcf8 into main Dec 9, 2025
10 of 13 checks passed
@chronark chronark deleted the feat/env-vars-ctrl-decryption branch December 9, 2025 16:14
@vercel vercel bot temporarily deployed to Preview – dashboard December 9, 2025 16:16 Inactive
mcstepp pushed a commit that referenced this pull request Dec 9, 2025
* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
Flo4604 added a commit that referenced this pull request Dec 10, 2025
* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>
chronark added a commit that referenced this pull request Dec 19, 2025
* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

* feat: inject env vars into pod spec via Krane

* feat: add customer-workload service account for pod isolation

* remove gw from k8s manifest, add agent fix ctrl vault for certs

* seperate master keys too

* add inital webhook stuff

* add generated stuff

* adjust comments

* use otel lgtm stack in k8s too

* fix some rabbit comments

* fix some rabbit comments

* get rid of some unncessary comments

* actually add unkey env cmd gitignores...

* fix golint issues

* Fix/update validation issues status label (#4478)

* fix: update API key status label from 'Potential issues' to 'High Error Rate'

Changed the validation-issues status label to more clearly communicate
that the key is receiving invalid requests, rather than implying the
API or key itself is broken.

Changes:
- Label: 'Potential issues' → 'High Error Rate'
- Tooltip: Updated to clarify that requests are invalid (rate limited,
  unauthorized, etc.) rather than suggesting system issues

Fixes #4474

* chore: apply biome formatting

* fix: update status label to 'Elevated Rejections' per review

---------

Co-authored-by: CodeReaper <148160799+MichaelUnkey@users.noreply.github.com>

* chore: Remove un-used UI components (#4472)

* removed un used components

* updated members refs

---------

Co-authored-by: James P <james@unkey.dev>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* perf: fix n+1 (#4484)

* fix: add 403 error when 0 key verification perms (#4483)

* fix: add 403 error when 0 key verification perms

* cleanup tests

* feat: add environment variables db schema and queries (#4450)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars (#4451)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* feat: add GetPullToken

* feat: dashboard UI for environment variables management (#4452)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* feat: decrypt env vars in CTRL workflow before passing to Krane (#4453)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* feat: inject env vars into pod spec via Krane (#4454)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

* feat: inject env vars into pod spec via Krane

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* feat: add customer-workload service account for pod isolation (#4455)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

* feat: inject env vars into pod spec via Krane

* feat: add customer-workload service account for pod isolation

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* remove gw from k8s manifest, add agent fix ctrl vault for certs (#4463)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

* feat: inject env vars into pod spec via Krane

* feat: add customer-workload service account for pod isolation

* remove gw from k8s manifest, add agent fix ctrl vault for certs

* seperate master keys too

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* chore: Make Stripe Great Again (#4479)

* fix: Make stripe webhooks more robust

* chore: Move alert to UI (#4485)

* Moved alert to ui and swapped usages

* feat: better env var injection (#4468)

* feat: add environment variables db schema and queries

* fix db query

* feat: add SecretsConfig proto for encrypted env vars

* [autofix.ci] apply automated fixes

* feat: dashboard UI for environment variables management

* fix comment and rename file

* fix file export name

* Remove unnecessary comments from add-env-vars

* add toasts for environment variable operations

* [autofix.ci] apply automated fixes

* fix: add try/catch error handling to env var mutations

* unfmt file

* [autofix.ci] apply automated fixes

* feat: decrypt env vars in CTRL workflow before passing to Krane

* feat: inject env vars into pod spec via Krane

* feat: add customer-workload service account for pod isolation

* remove gw from k8s manifest, add agent fix ctrl vault for certs

* seperate master keys too

* add inital webhook stuff

* add generated stuff

* adjust comments

* use otel lgtm stack in k8s too

* fix some rabbit comments

* fix some rabbit comments

* get rid of some unncessary comments

* actually add unkey env cmd gitignores...

* fix golint issues (#4477)

* [autofix.ci] apply automated fixes

* fix fmt

* linter be happy

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andreas Thomas <dev@chronark.com>

* make token pod owned

* feat: add lets encrypt challenges (#4471)

* feat: add lets encrypt challenges

* always disable cname following

* cleanup some code

* cleanup some code

* cleanup some code

* cleanup some code

* cleanup some code

* fix golint issues

* fix golint issues

* fmt

* remove old webhook code

* remove old webhook code

* make build id not optiona

* cleanup

* cleanup

* fmt

* fmt

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: abhay <88815641+theabhayprajapati@users.noreply.github.com>
Co-authored-by: CodeReaper <148160799+MichaelUnkey@users.noreply.github.com>
Co-authored-by: James P <james@unkey.dev>
Co-authored-by: Andreas Thomas <dev@chronark.com>
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