forked from bbl/secretize
-
Notifications
You must be signed in to change notification settings - Fork 0
Add KRM exec and Docker functions support #1
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
Open
aabouzaid
wants to merge
16
commits into
DevOpsHiveHQ:main
Choose a base branch
from
AhmedElsayed101:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6222af0
Fix the parsing issue for strings to avoid errors with multible = in it
AhmedElsayed101 d403dad
Add KRM support
AhmedElsayed101 b580892
Update README file
AhmedElsayed101 39373b1
Add test cases
AhmedElsayed101 53e9226
Update the libraries versions and add kyaml
AhmedElsayed101 d9211eb
Add updated go.sum
AhmedElsayed101 8eddbcb
Add docker file
AhmedElsayed101 a41c603
Create dockerignore file
AhmedElsayed101 4c343b6
Create examples for each approach
AhmedElsayed101 d75f8e0
Update the imports and Harden the nginx version
AhmedElsayed101 85c5754
tidy up ci.yaml
aabouzaid 9944cbe
Update ci.yaml
aabouzaid c5432f0
ci: update golang setup step
aabouzaid e18b65e
Update versions
AhmedElsayed101 49daf35
Update dependencies versions
AhmedElsayed101 cffde3d
Fix instructions
AhmedElsayed101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Test infrastructure (causes permission issues) | ||
| test-infrastructure/ | ||
|
|
||
| # Git files | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # Documentation | ||
| *.md | ||
| docs/ | ||
|
|
||
| # Examples (not needed for build) | ||
| examples/ | ||
|
|
||
| # Test files | ||
| *_test.go | ||
| test/ | ||
|
|
||
| # IDE files | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Build artifacts | ||
| bin/ | ||
| dist/ | ||
| *.exe | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Temporary files | ||
| tmp/ | ||
| temp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Build stage | ||
| FROM golang:1.19-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| COPY . . | ||
| RUN CGO_ENABLED=0 GOOS=linux go build -o /secretize ./cmd/secretize | ||
|
|
||
| # Final stage | ||
| FROM alpine:3.18 | ||
|
|
||
| # Install ca-certificates for HTTPS connections | ||
| RUN apk --no-cache add ca-certificates | ||
|
|
||
| COPY --from=builder /secretize /usr/local/bin/secretize | ||
|
|
||
| # KRM functions run as nobody user | ||
| USER nobody | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/secretize"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Containerized KRM Function Example (Environment Variables) | ||
|
|
||
| This example demonstrates how to use Secretize as a containerized KRM function with Kustomize, sourcing secrets from environment variables set directly in the function config. | ||
|
|
||
| --- | ||
|
|
||
| ## How It Works | ||
|
|
||
| - The containerized KRM function runs in an isolated environment and **does not inherit environment variables from your shell**. | ||
| - All required environment variables must be set explicitly in the `envs:` section of the function config in `secret-generator.yaml`. | ||
| - This approach is simple, reproducible, and works reliably with Kustomize and Secretize. | ||
|
|
||
| --- | ||
|
|
||
| ## Step-by-Step Usage | ||
|
|
||
| 1. **(Optional) Build the Secretize Docker image (if using `image: secretize:local`):** | ||
| ```bash | ||
| cd ../../.. | ||
| docker build -t secretize:local . | ||
| cd examples/docker/env | ||
| ``` | ||
|
|
||
| 2. **Export the required environment variables in your shell:** | ||
| ```bash | ||
| export DATABASE_URL="postgresql://user:pass@localhost/db" | ||
| export API_KEY="your-secret-api-key" | ||
| export JWT_SECRET="your-jwt-secret" | ||
| export CONFIG_JSON='{"feature_new_ui": "true", "feature_beta": "false"}' | ||
| ``` | ||
| These variables will be referenced by the YAML configuration. | ||
|
|
||
| 3. **Reference the environment variables in your YAML file:** | ||
| In `secret-generator.yaml`, you can reference these variables using the `literals` and `kv` fields: | ||
| ```yaml | ||
| sources: | ||
| - provider: env | ||
| literals: | ||
| - DATABASE_URL # Reads from $DATABASE_URL | ||
| - API_KEY # Reads from $API_KEY | ||
| - JWT_SECRET # Reads from $JWT_SECRET | ||
| kv: | ||
| - CONFIG_JSON # Reads from $CONFIG_JSON and parses as JSON | ||
| ``` | ||
| - `literals`: Direct environment variable values | ||
| - `kv`: Environment variables containing JSON that gets parsed into key-value pairs | ||
|
|
||
| 4. **Run Kustomize build with containerized KRM function enabled:** | ||
| ```bash | ||
| kustomize build --enable-alpha-plugins . | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Why Not YAML Anchors for Env Vars? | ||
| - YAML anchors are useful for repeating static YAML blocks, but **they do not help with dynamic environment variable substitution**. | ||
| - For dynamic values, set them directly in the `envs:` list as shown above. | ||
| - If you want to use exported environment variables from your shell, use the [exec approach](../exec/env/README.md) instead. | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - If secrets are not found, make sure you set all required env vars in the function config. | ||
| - If you see an error about `secretize:local` not found, make sure you built the image as described above. | ||
| - If you see errors about `$` or `${VAR}` in the output, make sure you have replaced all placeholders with actual values. | ||
|
|
||
| --- | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| - **Never hardcode real secrets in your configs for production.** | ||
| - Use this approach for local development, testing, or with non-sensitive values. | ||
| - For production, consider using a secrets manager (like Vault) and the appropriate Secretize provider. | ||
|
|
||
| --- | ||
|
|
||
| ## Reference: Using Host Environment Variables | ||
|
|
||
| - If you want to use environment variables exported in your shell, use the [exec KRM function approach](../exec/env/README.md), which can access your host environment directly. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.