-
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.
Add tests, docs and update Dockerfile
- Loading branch information
Adam Talbot
committed
Jun 17, 2018
1 parent
88ac79b
commit f0d6f0b
Showing
8 changed files
with
259 additions
and
21 deletions.
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
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,13 +1,19 @@ | ||
FROM golang:1.10.3-alpine as build | ||
FROM golang:1.10.3 as build | ||
|
||
RUN apk add --no-cache git openssh ca-certificates | ||
RUN wget -O - https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
ARG DEP_VERSION=0.4.1 | ||
|
||
# install dep | ||
RUN wget -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 && \ | ||
chmod +x /usr/local/bin/dep | ||
|
||
# add code | ||
ADD . /go/src/github.com/thatsmrtalbot/k8s-vault-csr | ||
WORKDIR /go/src/github.com/thatsmrtalbot/k8s-vault-csr | ||
RUN dep ensure -vendor-only -v | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o /bin/k8s-vault-csr ./cmd/k8s-vault-csr | ||
|
||
FROM scratch | ||
# vendor and build | ||
RUN make bin/linux_amd64/k8s-vault-csr USE_DOCKER=0 VENDOR_ONLY=1 | ||
|
||
COPY --from=build /bin/k8s-vault-csr /bin/k8s-vault-csr | ||
# final container | ||
FROM scratch | ||
COPY --from=build /go/src/github.com/thatsmrtalbot/k8s-vault-csr/bin/linux_amd64/k8s-vault-csr /bin/k8s-vault-csr | ||
ENTRYPOINT [ "/bin/k8s-vault-csr" ] |
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
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
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,61 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: kube-vault-signer | ||
namespace: kube-system | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: kube-vault-signer | ||
rules: | ||
- apiGroups: | ||
- certificates.k8s.io | ||
resources: | ||
- certificatesigningrequests | ||
- certificatesigningrequests/status | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- patch | ||
- update | ||
--- | ||
kind: CluterRoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
metadata: | ||
name: kube-vault-signer | ||
subjects: | ||
- kind: ServiceAccount | ||
name: kube-vault-signer | ||
namespace: kube-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: kube-vault-signer | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kube-vault-signer | ||
namespace: kube-system | ||
labels: | ||
k8s-app: kube-vault-signer | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
k8s-app: kube-vault-signer | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: kube-vault-signer | ||
spec: | ||
serviceAccountName: kube-vault-signer | ||
containers: | ||
- name: kube-vault-signer | ||
image: thatsmrtalbot/kube-vault-signer:0.0.1 | ||
args: | ||
- -vault-address=https://vault.example.com | ||
- -use-kubernetes-auth=true | ||
- -kubernetes-auth-role=kube-vault-signer |
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
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,108 @@ | ||
package token | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
log "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/vault/api" | ||
"github.com/hashicorp/vault/helper/logging" | ||
"github.com/hashicorp/vault/http" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/physical/inmem" | ||
"github.com/hashicorp/vault/vault" | ||
) | ||
|
||
func TestRenewer(t *testing.T) { | ||
// Set up vault | ||
|
||
logger := logging.NewVaultLogger(log.Trace) | ||
|
||
phys, err := inmem.NewInmem(nil, logger) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
|
||
core, err := vault.NewCore(&vault.CoreConfig{ | ||
Physical: phys, | ||
LogicalBackends: map[string]logical.Factory{}, | ||
DisableMlock: true, | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal("error initializing core: ", err) | ||
return | ||
} | ||
|
||
init, err := core.Initialize(context.Background(), &vault.InitParams{ | ||
BarrierConfig: &vault.SealConfig{ | ||
SecretShares: 1, | ||
SecretThreshold: 1, | ||
}, | ||
RecoveryConfig: nil, | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal("error initializing core: ", err) | ||
return | ||
} | ||
|
||
if unsealed, err := core.Unseal(init.SecretShares[0]); err != nil { | ||
t.Fatal("error unsealing core: ", err) | ||
return | ||
} else if !unsealed { | ||
t.Fatal("vault shouldn't be sealed") | ||
return | ||
} | ||
|
||
ln, addr := http.TestServer(nil, core) | ||
defer ln.Close() | ||
|
||
clientConfig := api.DefaultConfig() | ||
clientConfig.Address = addr | ||
client, err := api.NewClient(clientConfig) | ||
|
||
if err != nil { | ||
t.Fatal("error initializing HTTP client: ", err) | ||
return | ||
} | ||
|
||
client.SetToken(init.RootToken) | ||
|
||
// Set token | ||
|
||
secret, err := client.Auth().Token().Create(&api.TokenCreateRequest{ | ||
TTL: "3600", | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal("error creating child token: ", err) | ||
return | ||
} | ||
|
||
client.SetToken(secret.Auth.ClientToken) | ||
|
||
// Test case | ||
|
||
renewer := NewRenewer(client, nil) | ||
status, err := renewer.currentTokenStatus() | ||
|
||
if err != nil { | ||
t.Errorf("error getting token status: %s", err) | ||
} | ||
|
||
if !status.HasToken { | ||
t.Error("no token") | ||
} | ||
|
||
if status.Expired { | ||
t.Error("token is expired") | ||
} | ||
|
||
err = renewer.renew() | ||
|
||
if err != nil { | ||
t.Errorf("error renewing token: %s", err) | ||
} | ||
} |
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