Skip to content

Commit

Permalink
Introduce Secrets Manager resource
Browse files Browse the repository at this point in the history
Introduce initial version of the secrets manager resource.
  • Loading branch information
HeavyWombat committed Sep 15, 2023
0 parents commit a59bc20
Show file tree
Hide file tree
Showing 19 changed files with 881 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.dockerignore
.github
unit.coverprofile
Dockerfile
LICENSE
Makefile
README.md
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
target-branch: main
27 changes: 27 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Dependabot auto-merge

on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Enable auto-merge for Dependabot PRs
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
gh pr review --approve "$PR_URL"
gh pr merge --auto --merge "$PR_URL"
30 changes: 30 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: golangci-lint

on:
push:
tags-ignore:
- '**'
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
only-new-issues: true
30 changes: 30 additions & 0 deletions .github/workflows/misspell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: spellcheck

on:
push:
tags-ignore:
- '**'
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: spellcheck
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Spellcheck
run: |
go install github.com/client9/misspell/cmd/misspell@latest
find . -type f | xargs misspell -source=text -error
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Release Secrets Manager Resource Image

on:
push:
branches:
- main

jobs:
image:
if: ${{ github.repository == 'homeport/secrets-manager-resource' }}
runs-on: ubuntu-latest
permissions:
packages: write

env:
IMAGE_HOST: ghcr.io
IMAGE_NAME: ${{ github.repository }}

steps:
- uses: actions/checkout@v4
- name: Build and push container image
env:
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_USERNAME: ${{ github.repository_owner }}
DOCKER_BUILDKIT: "1"
BUILDKIT_PROGRESS: plain
run: |
docker login \
--username "$REGISTRY_USERNAME" \
--password-stdin \
"$IMAGE_HOST" <<<"$REGISTRY_PASSWORD"
docker build \
--push \
--tag "${IMAGE_HOST}/${IMAGE_NAME}:latest" \
.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unit.coverprofile
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright © 2023 The Homeport Team
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

FROM golang:1.20 as bootstrap
WORKDIR /go/src/github.com/homeport/secrets-manager-resource
COPY . .

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOARCH amd64
RUN --mount=type=cache,target=/root/.cache/go-build \
mkdir -p /tmp/dist/opt/resource && \
go build \
-trimpath \
-ldflags "-s -w -extldflags '-static'" \
-o /tmp/dist/opt/resource \
./cmd/...


FROM alpine:latest
COPY --from=bootstrap /tmp/dist /
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 The Homeport Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Secrets Manager Resource

Concourse resource for secrets stored in IBM Cloud Secrets Manager instances.

## Source Configuration

- **endpointURL**: _Required_ Endpoint URL of the Secrets Manager instance to connect to, see [secrets manager docs](https://cloud.ibm.com/apidocs/secrets-manager/secrets-manager-v2?code=go#endpoints) for more details.
- **apikey**: _Required_ API key that allows access to read from the respective secrets manager instance.
- **secretName**: _Required_ Name of the secret in the secrets manager instance. This is the name, not the ID of the secret. The secret will be searched for by name through the API.

### Example

Since it is a custom resource type, it has to be configured once in the pipeline configuration.

```yaml
resource_types:
- name: secrets-manager-resource
type: docker-image
source:
repository: ghcr.io/homeport/secrets-manager-resource
tag: latest
```
One example would be to trigger a job, if the secret was updated in Secrets Manager.
``` yaml
resources:
- name: some-secret
type: secrets-manager-resource
check_every: 2h
icon: key
source:
endpointURL: https://<instance-id>.<region>.secrets-manager.appdomain.cloud
apikey: ((your-api-key))
secretName: super-important-secret

jobs:
- name: some-job
plan:
- get: some-secret
trigger: true
- task: some-task
config:
inputs:
- name: some-secret
run:
path: /bin/bash
args:
- -c
- |
#!/bin/bash
some-tool login --secret $(< some-secret/payload)
```
## Behavior
### `check`: Checks for _updated at_ of a secret

Checks whether it finds a secret by the provided name and returns the last _updated at_ time.

### `in`: Obtains the secret data

Gets the secret by name and creates files based on the secret fields. Different secret types will create different files since they have different fields in Secret Manager. Check the [Working with secrets of different types](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-what-is-secret#secret-types) for more details on the types and their respective fields.

### `out`: No-op

Not implemented. May be subject to change in the future.

## Development

### Prerequisites

- Go is _Required_ - version 1.20 is in use, newer versions will probably work.
- Docker or similar is _Required_ - any tool that allows for a `docker build` like container build.

### Contributing

Please make all pull requests to the `main` branch and ensure tests pass locally.
35 changes: 35 additions & 0 deletions cmd/check/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2023 The Homeport Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import (
"fmt"
"os"

"github.com/homeport/secrets-manager-resource/internal/smr"
)

func main() {
if err := smr.Check(os.Stdin); err != nil {
fmt.Fprintf(os.Stderr, "check failed: %v", err)
os.Exit(1)
}
}
39 changes: 39 additions & 0 deletions cmd/in/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © 2023 The Homeport Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import (
"fmt"
"os"

"github.com/homeport/secrets-manager-resource/internal/smr"
)

func main() {
if len(os.Args) < 2 {
panic("invalid state, no target directory provided")
}

if err := smr.In(os.Stdin, os.Args[1]); err != nil {
fmt.Fprintf(os.Stderr, "get failed: %v", err)
os.Exit(1)
}
}
31 changes: 31 additions & 0 deletions cmd/out/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2023 The Homeport Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import (
"fmt"
"os"
)

func main() {
fmt.Println("out is not supported")
os.Exit(1)
}
Loading

0 comments on commit a59bc20

Please sign in to comment.