-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from retailnext/initial_check_in
Initial check in
- Loading branch information
Showing
30 changed files
with
2,326 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,81 @@ | ||
--- | ||
name: CI | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
env: | ||
# renovate: datasource=github-releases depName=golangci/golangci-lint versioning=semver-coerced | ||
GOLANGCI_LINT_VERSION: "v1.59.0" | ||
IMAGE_NAME: "${{ github.repository }}" | ||
TAG: "ghcr.io/${{ github.repository }}:latest" | ||
TEST_PARAMS: "--vault-addr localhost:1234 --initout file:/secret_out.txt --dry-run" | ||
REGISTRY: "ghcr.io" | ||
jobs: | ||
go: | ||
name: Go | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@23faadfdeb23a6f9e511beaba149bb123b5b145a # v6 | ||
with: | ||
version: ${{ env.GOLANGCI_LINT_VERSION }} | ||
args: --timeout=10m | ||
- name: go test | ||
run: | | ||
go test -v ./... | ||
- name: run vault-init | ||
run: | | ||
go build -o vault-init . | ||
./vault-init ${{ env.TEST_PARAMS }} | ||
docker: | ||
name: Docker Build vault-init | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3 | ||
- name: Log in to the Container registry | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build test image | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5 | ||
with: | ||
context: . | ||
push: false | ||
load: true | ||
tags: ${{ env.TAG }} | ||
cache-from: type=gha | ||
- name: Test image | ||
run: | | ||
docker run --rm ${{ env.TAG }} ${{ env.TEST_PARAMS }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=pr | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | ||
- name: Build images | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: ${{ github.ref == 'refs/heads/main' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
This file contains 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,14 @@ | ||
FROM golang:1.22@sha256:ab48cd7b8e2cffb6fa1199de232f61c76d3c33dc158be8a998c5407a8e5eb583 as builder | ||
|
||
WORKDIR / | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY *.go ./ | ||
COPY pkgs ./pkgs | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o /vault-init -trimpath . | ||
|
||
FROM gcr.io/distroless/base:latest@sha256:786007f631d22e8a1a5084c5b177352d9dcac24b1e8c815187750f70b24a9fc6 | ||
WORKDIR / | ||
COPY --from=builder /vault-init /vault-init | ||
ENTRYPOINT ["/vault-init"] |
This file contains 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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# vault-init | ||
When a new hashicorp vault cluster starts, it needs to be initialized. The code handles the initialization and plus | ||
When a new hashicorp vault cluster starts, it needs to be initialized. The code handles the initialization and some tasks after the initialization | ||
|
||
## Vault initialization for vault managed by Terraform Cloud | ||
|
||
`vault-init` initializes the vault in the given address and | ||
saves the output to a gcp/aws secret or file. **Currently it does | ||
NOT handle unseal process and it assumes that auto unseal is | ||
implemented already (usually through KMS).** | ||
After the intialization, with the initial root token, `vault-init` | ||
can perform the following tasks | ||
- Set up policies; in order for the authentication to work properly, | ||
policies need to be set. Typically, `admin` policy can be set | ||
through this task. | ||
- Set up `jwt` type auth for oidc; oidc configuration and the initial | ||
role can be set up. Typically, `admin` role is set up with the policy | ||
created in the previous "policy task". For example, the role of | ||
terraform agent and workspace for vault ACL can be set up through | ||
this task. Refer to https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/vault-configuration for details |
This file contains 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,34 @@ | ||
- type: policy | ||
task: | ||
name: admin | ||
policy_content: | | ||
path "sys/leases/*" | ||
{ | ||
capabilities = ["create", "read", "update", "delete", "list", "sudo"] | ||
} | ||
path "auth/*" | ||
{ | ||
capabilities = ["create", "read", "update", "delete", "list", "sudo"] | ||
} | ||
path "sys/auth/*" | ||
{ | ||
capabilities = ["create", "read", "update", "delete", "list", "sudo"] | ||
} | ||
path "sys/auth" | ||
{ | ||
capabilities = ["read"] | ||
} | ||
- type: oidc_auth | ||
task: | ||
auth_path: jwt | ||
oidc_discovery_url: "https://app.terraform.io" | ||
bound_issuer: "https://app.terraform.io" | ||
role: | ||
name: tfc-agent | ||
policy_names: | ||
- admin | ||
bound_audiences: | ||
- vault.workload.identity | ||
bound_claim_sub: "organization:my-org-name:project:my-project-name:workspace:my-workspace-name:run_phase:*" | ||
user_claim: terraform_full_workspace | ||
ttl: 20m |
This file contains 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,119 @@ | ||
module github.com/retailnext/vault-init | ||
|
||
go 1.22.1 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go-v2 v1.26.1 | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/testcontainers/testcontainers-go v0.31.0 | ||
github.com/testcontainers/testcontainers-go/modules/vault v0.31.0 | ||
github.com/urfave/cli/v2 v2.27.2 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/auth v0.3.0 // indirect | ||
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect | ||
cloud.google.com/go/compute/metadata v0.3.0 // indirect | ||
cloud.google.com/go/iam v1.1.7 // indirect | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/Microsoft/hcsshim v0.11.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect | ||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect | ||
github.com/aws/smithy-go v1.20.2 // indirect | ||
github.com/cenkalti/backoff/v3 v3.2.2 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||
github.com/containerd/containerd v1.7.15 // indirect | ||
github.com/containerd/log v0.1.0 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/distribution/reference v0.5.0 // indirect | ||
github.com/docker/docker v25.0.5+incompatible // indirect | ||
github.com/docker/go-connections v0.5.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/felixge/httpsnoop v1.0.4 // indirect | ||
github.com/go-jose/go-jose/v4 v4.0.1 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-ole/go-ole v1.2.6 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.4 // indirect | ||
github.com/google/s2a-go v0.1.7 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect | ||
github.com/googleapis/gax-go/v2 v2.12.3 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect | ||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect | ||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect | ||
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect | ||
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect | ||
github.com/hashicorp/go-sockaddr v1.0.6 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/klauspost/compress v1.16.0 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/moby/patternmatcher v0.6.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/sys/user v0.1.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect | ||
github.com/ryanuber/go-glob v1.0.0 // indirect | ||
github.com/shirou/gopsutil/v3 v3.23.12 // indirect | ||
github.com/shoenig/go-m1cpu v0.1.6 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/tklauser/go-sysconf v0.3.12 // indirect | ||
github.com/tklauser/numcpus v0.6.1 // indirect | ||
github.com/yusufpapurcu/wmi v1.2.3 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect | ||
go.opentelemetry.io/otel v1.24.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.24.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.24.0 // indirect | ||
golang.org/x/crypto v0.22.0 // indirect | ||
golang.org/x/mod v0.16.0 // indirect | ||
golang.org/x/net v0.24.0 // indirect | ||
golang.org/x/oauth2 v0.19.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/time v0.5.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
google.golang.org/api v0.177.0 // indirect | ||
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect | ||
google.golang.org/grpc v1.63.2 // indirect | ||
google.golang.org/protobuf v1.34.0 // indirect | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/secretmanager v1.13.0 | ||
github.com/aws/aws-sdk-go-v2/config v1.27.11 | ||
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 | ||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect | ||
github.com/hashicorp/vault/api v1.13.0 | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect | ||
) |
Oops, something went wrong.