Skip to content
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

spiffe-step-ssh server #198

Merged
merged 107 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
0b29b47
Initial prototype of spire-step-ssh integration
kfox1111 Jan 22, 2024
3bcfdcd
Ingress work, image cleanup and misc cleanup
kfox1111 Jan 22, 2024
f707eb3
More values rework
kfox1111 Jan 22, 2024
779909f
Merge branch 'main' into spire-step-ssh
kfox1111 Jan 24, 2024
5872a60
Merge branch 'main' into spire-step-ssh
kfox1111 Jan 24, 2024
a9635ca
Rename chart spiffe-step-ssh
kfox1111 Sep 20, 2024
8b2db1d
Merge branch 'main' into spire-step-ssh
kfox1111 Sep 20, 2024
a7eaadc
Update to use shared lib
kfox1111 Sep 20, 2024
0652acb
Update spiffe-helper
kfox1111 Sep 21, 2024
f7a6527
Use URLSAN rather then CN
kfox1111 Sep 22, 2024
bd333a4
Lookup the sans.
kfox1111 Sep 22, 2024
ae88813
Make trust domain configurable
kfox1111 Sep 23, 2024
fb3163f
Add flag
kfox1111 Sep 23, 2024
2de31ab
Make driver configurable
kfox1111 Sep 23, 2024
e1d3c09
Add more configurables. Fix up docs to pass test.
kfox1111 Sep 23, 2024
cac07e2
Add some metadata
kfox1111 Sep 23, 2024
29e8ad2
Fix metadata
kfox1111 Sep 23, 2024
58f4e5f
Add default values for lint
kfox1111 Sep 23, 2024
785aab2
Forgot values updates
kfox1111 Sep 23, 2024
72773fa
Fix metadata
kfox1111 Sep 23, 2024
60fced4
Start working on integration test
kfox1111 Sep 23, 2024
20ed47e
Test
kfox1111 Sep 23, 2024
746bdcf
Test
kfox1111 Sep 23, 2024
70e8fbe
Fix names
kfox1111 Sep 23, 2024
57dbd47
More test bits
kfox1111 Sep 23, 2024
34cdca4
More test bits
kfox1111 Sep 23, 2024
96946b9
More test bits
kfox1111 Sep 23, 2024
2e6e400
More test bits
kfox1111 Sep 23, 2024
bcf6829
More test bits
kfox1111 Sep 23, 2024
9889586
More test bits
kfox1111 Sep 23, 2024
5f8fb26
More fixes
kfox1111 Sep 23, 2024
8040713
More fixes
kfox1111 Sep 23, 2024
7669d0d
More fixes
kfox1111 Sep 23, 2024
397e6ba
Fix name conflict. Align naming
kfox1111 Sep 23, 2024
d7f504b
Fix name
kfox1111 Sep 23, 2024
c8dc02d
Add more logging
kfox1111 Sep 23, 2024
5216d3d
Disable unneeded test. Add missing file.
kfox1111 Sep 23, 2024
f5b06e6
Setup more things
kfox1111 Sep 23, 2024
3212352
Add missing conf file
kfox1111 Sep 23, 2024
40906fb
Fix multiple svids
kfox1111 Sep 23, 2024
54fd668
Merge branch 'main' into spire-step-ssh
kfox1111 Sep 23, 2024
9de84a1
Fix ci defaults
kfox1111 Sep 23, 2024
f6a1e50
Fix filename
kfox1111 Sep 23, 2024
74f63fc
Try and get the linter to stop complaining...
kfox1111 Sep 23, 2024
8788e03
Fix perms
kfox1111 Sep 23, 2024
897011d
More logs
kfox1111 Sep 23, 2024
1c2bf1c
More setup
kfox1111 Sep 23, 2024
0e5d7c0
Fixes
kfox1111 Sep 23, 2024
d1091f2
Fixes
kfox1111 Sep 23, 2024
ea49600
Add wait
kfox1111 Sep 23, 2024
b067c26
More logging
kfox1111 Sep 23, 2024
ffc00e1
Test ssh
kfox1111 Sep 23, 2024
5d91ebd
Restart fetchca on updates too
kfox1111 Sep 23, 2024
c82c3b0
Fix formating
kfox1111 Sep 23, 2024
15993cd
Add missing file flag
kfox1111 Sep 23, 2024
aa88671
Increase timeout
kfox1111 Sep 23, 2024
2bdf7fe
More flags
kfox1111 Sep 23, 2024
3f26dcd
Fix name
kfox1111 Sep 23, 2024
4fcaacb
Finish end to end test
kfox1111 Sep 23, 2024
e115eff
Fix ingress setting
kfox1111 Sep 23, 2024
4dfee9f
More logging/tests
kfox1111 Sep 23, 2024
e0c0044
More testing
kfox1111 Sep 23, 2024
e8332ce
Fix namespace
kfox1111 Sep 23, 2024
7052280
Fetch correct bundle
kfox1111 Sep 23, 2024
13ccb15
Chart testing will fail as it depends on spire to be preinstalled. We…
kfox1111 Sep 23, 2024
f28de40
Dont skip tls for testing
kfox1111 Sep 23, 2024
fec1787
More logging
kfox1111 Sep 23, 2024
a17fc17
More debug
kfox1111 Sep 23, 2024
b301aab
More debug
kfox1111 Sep 23, 2024
42fa6b4
Pass intermediates
kfox1111 Sep 23, 2024
1c50c1b
Fix trustdomain
kfox1111 Sep 23, 2024
69429b6
Add ca authority prefix
kfox1111 Sep 23, 2024
112fa6e
fix
kfox1111 Sep 23, 2024
5674ff6
fix
kfox1111 Sep 23, 2024
4c8af65
fix
kfox1111 Sep 23, 2024
8dba008
ci test is just broken. Revert trying to fix it.
kfox1111 Sep 24, 2024
cc5de37
Update charts/spiffe-step-ssh/files/ssh_x5c.tpl
kfox1111 Sep 24, 2024
96b2c71
Self review feedback
kfox1111 Sep 24, 2024
1b5e374
Merge branch 'spire-step-ssh' of https://github.com/spiffe/helm-chart…
kfox1111 Sep 24, 2024
888a4bb
Switch ingress to our more functional/easy type
kfox1111 Sep 24, 2024
769e945
Simplify the template
kfox1111 Sep 24, 2024
fccd986
Add cast
kfox1111 Sep 24, 2024
290d615
Add install notes
kfox1111 Sep 25, 2024
7696ffb
Fix test
kfox1111 Sep 26, 2024
804dcb6
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 5, 2024
605ee78
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 7, 2024
d2995e7
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 7, 2024
4e5e168
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 8, 2024
a2d70ba
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 10, 2024
07375b7
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 14, 2024
d7e6736
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 19, 2024
2ad288d
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 21, 2024
c40de60
Update tests for updated client
kfox1111 Oct 26, 2024
96a574c
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 26, 2024
31a613a
Fix logging and entry
kfox1111 Oct 26, 2024
638912a
Add missing dir
kfox1111 Oct 26, 2024
0d7058a
Fix file location
kfox1111 Oct 26, 2024
a24a8d7
Update timeout
kfox1111 Oct 26, 2024
ffbd99d
More logging
kfox1111 Oct 26, 2024
898828c
Fix filename
kfox1111 Oct 26, 2024
f3cd0f2
Fix perms
kfox1111 Oct 26, 2024
f33b39d
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 28, 2024
3b46554
Merge branch 'main' into spire-step-ssh
kfox1111 Oct 30, 2024
8dbd566
Merge branch 'main' into spire-step-ssh
kfox1111 Nov 3, 2024
e8d0908
Update charts/spiffe-step-ssh/README.md
kfox1111 Nov 3, 2024
f99df63
Merge branch 'main' into spire-step-ssh
kfox1111 Nov 4, 2024
b0b1f72
Apply suggestions from code review
kfox1111 Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ while true; do
done
)

common_test_file_exists () (
count=20
while true; do
if [ -f "$1" ]; then exit 0; fi
sleep 2
count=$((count-1))
[ $count -le 0 ] && exit 1
done
)

# Used just for testing. You should provide your own values as described in the install instructions.
common_test_your_values () {
cat > /tmp/$$.example-your-values.yaml <<EOF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/helm-chart-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
- name: Run chart-testing (install)
run: |
helm install -n spire-server spire-crds charts/spire-crds
ct install --config ct.yaml --excluded-charts spire-crds \
ct install --config ct.yaml --excluded-charts spire-crds,spiffe-step-ssh \
--target-branch ${{ github.base_ref }}

- name: Test summary
Expand Down
42 changes: 42 additions & 0 deletions charts/spiffe-step-ssh/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: v2
name: spiffe-step-ssh
description: sshd signed host certificates using SPIFFE for trust and step CA

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

keywords: ["spiffe", "step", "step-ca", "ssh"]
home: https://github.com/spiffe/helm-charts-hardened/tree/main/charts/spiffe-step-ssh
sources:
- https://github.com/spiffe/helm-charts-hardened/tree/main/charts/spiffe-step-ssh
icon: https://spiffe.io/img/logos/spire/icon/color/spire-icon-color.png
maintainers:
- name: kfox1111
email: [email protected]

dependencies:
- name: spire-lib
repository: file://../spire/charts/spire-lib
version: 0.1.0
- name: step-certificates
alias: step
repository: https://smallstep.github.io/helm-charts/
version: 1.27.4
65 changes: 65 additions & 0 deletions charts/spiffe-step-ssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
spire-values.yaml
```
spire-server:
nodeAttestor:
httpChallenge:
enabled: true
controllerManager:
identities:
clusterSPIFFEIDs:
spiffe-step-ssh-config:
type: raw
namespaceSelector:
matchLabels:
"kubernetes.io/metadata.name": default
podSelector:
matchLabels:
app: spiffe-step-ssh
component: config
spiffe-step-ssh-fetchca:
type: raw
namespaceSelector:
matchLabels:
"kubernetes.io/metadata.name": default
podSelector:
matchLabels:
app: spiffe-step-ssh
component: fetchca
dnsNameTemplates:
- "spiffe-step-ssh-fetchca.{{ .TrustDomain }}"
```

```shell
helm upgrade --install -n spire-server spire-crds spire-crds --repo https://spiffe.github.io/helm-charts-hardened/ --create-namespace
helm upgrade --install -n spire-server spire spire --repo https://spiffe.github.io/helm-charts-hardened/ -f spire-values.yaml --set global.spire.ingressControllerType=ingress-nginx,spire-server.ingress.enabled=true
```

```shell
helm upgrade --install ingress-nginx ingress-nginx -n ingress-nginx --create-namespace --repo https://kubernetes.github.io/ingress-nginx --set controller.service.type=ClusterIP,controller.service.externalIPs[0]=$(minikube ip) --set controller.watchIngressWithoutClass=true --set controller.extraArgs.enable-ssl-passthrough=
```

```shell
PASSWORD=$(openssl rand -base64 48)
echo "$PASSWORD" > spiffe-step-ssh-password.txt
step ca init --helm --deployment-type=Standalone --name='My CA' --dns spiffe-step-ssh.example.org --ssh --address :8443 --provisioner default --password-file spiffe-step-ssh-password.txt > spiffe-step-ssh-values.yaml
```

ingress-values.yaml
```yaml
global:
spiffe:
ingressControllerType: ingress-nginx
stepIngress:
enabled: true
fetchCA:
ingress:
enabled: true
```

```shell
helm upgrade --install spiffe-step-ssh . --set caPassword=`cat spiffe-step-ssh-password.txt` -f spiffe-step-ssh-values.yaml -f ingress-values.yaml --set trustDomain=example.org
```

<!-- The parameters section is generated using helm-docs.sh and should not be edited by hand. -->

## Parameters
1 change: 1 addition & 0 deletions charts/spiffe-step-ssh/ci/default-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trustDomain: example.org
13 changes: 13 additions & 0 deletions charts/spiffe-step-ssh/files/ssh_x5c.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if eq (len .AuthorizationCrt.URIs) 1 }}
{{- $san := printf "%s" (index .AuthorizationCrt.URIs 0) }}
{{- if hasPrefix "spiffe://@TRUST_DOMAIN@/@PREFIX@/" $san }}
{{- $name := trimPrefix "spiffe://@TRUST_DOMAIN@/@PREFIX@/" $san }}
{
"type": {{ toJson .Type }},
"keyId": {{ toJson $name }},
"principals": [{{ toJson $name }}],
"extensions": {{ toJson .Extensions }},
"criticalOptions": {{ toJson .CriticalOptions }}
}
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/spiffe-step-ssh/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Installed {{ .Chart.Name }}…

Configure your ssh clients with known_hosts file with:

@cert-authority *.{{ .Values.trustDomain }} {{ .Values.inject.certificates.ssh_host_ca }}
83 changes: 83 additions & 0 deletions charts/spiffe-step-ssh/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "spiffe-step-ssh.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "spiffe-step-ssh.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "spiffe-step-ssh.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "spiffe-step-ssh.labels" -}}
helm.sh/chart: {{ include "spiffe-step-ssh.chart" . }}
{{ include "spiffe-step-ssh.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "spiffe-step-ssh.selectorLabels" -}}
app.kubernetes.io/name: {{ include "spiffe-step-ssh.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "spiffe-step-ssh.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "spiffe-step-ssh.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/* Takes in a dictionary with keys:
* global - the standard global object
* ingress - a standard format ingress config object
*/}}
{{- define "spiffe-step-ssh.ingress-controller-type" }}
{{- $type := "" }}
{{- if ne (len (dig "spiffe" "ingressControllerType" "" .global)) 0 }}
{{- $type = .global.spiffe.ingressControllerType }}
{{- else if ne .ingress.controllerType "" }}
{{- $type = .ingress.controllerType }}
{{- else if (dig "openshift" false .global) }}
{{- $type = "openshift" }}
{{- else }}
{{- $type = "other" }}
{{- end }}
{{- if not (has $type (list "ingress-nginx" "openshift" "other")) }}
{{- fail "Unsupported ingress controller type specified. Must be one of [ingress-nginx, openshift, other]" }}
{{- end }}
{{- $type }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/spiffe-step-ssh/templates/config-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "spiffe-step-ssh.fullname" . }}-config-deployment
labels:
{{- include "spiffe-step-ssh.labels" . | nindent 4 }}
data:
spiffe-helper.conf: |
agent_address = "/spiffe-workload-api/spire-agent.sock"
cmd = "sh"
cmd_args = "/config-deployment/update.sh"
cert_dir = "/certs"
svid_file_name = "tls.crt"
svid_key_file_name = "tls.key"
svid_bundle_file_name = "ca.pem"
add_intermediates_to_bundle = false
update.sh: |
#!/bin/sh
export ROOTS=$(base64 /certs/ca.pem | tr '\n' ' ' | sed 's/ //g')
echo Updating Roots to "$ROOTS"
cat /config/ca.json > /work/ca.json
yq e -i -ojson '.authority.provisioners |= map(select(.name == "x5c@spiffe").roots = env(ROOTS))' /work/ca.json
/helper/kubectl create configmap {{ include "spiffe-step-ssh.fullname" . }}-config -n "{{ .Release.Namespace }}" --from-file=/work/ca.json --from-file=/config/defaults.json --from-file=/config/ssh_x5c.tpl --dry-run=client -o yaml | /helper/kubectl apply -f -
/helper/kubectl rollout restart statefulset {{ include "spiffe-step-ssh.fullname" . }} -n "{{ .Release.Namespace }}"
echo $?
Loading
Loading