Skip to content

Commit 87422db

Browse files
authored
Merge pull request #14 from MbolotSuse/certs-no-root
Adding support for custom CAs and fixing bugs
2 parents 87cc1eb + 5879896 commit 87422db

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

README.md

+42-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,49 @@ The CSP adapter also produces a configmap with Cloud provider specific informati
1212
can be used by rancher to produce a supportconfig (tar which can be given to support).
1313

1414
## Installation
15-
NOTE: The CSP adapter requires rancher to be installed before use (rancher provides node metrics and other important features).
1615

17-
TODO
16+
Full installation steps can be found in the rancher docs.
17+
18+
This chart requires:
19+
20+
- Rancher version 2.6.6 or higher
21+
- Rancher is installed on an EKS cluster
22+
- An IAM role has been configured according to the auth section of the readme and these docs
23+
- Any private certs have been provided as described in these docs
24+
25+
### Certificate Setup
26+
27+
The adapter communicates with rancher to get accurate node counts. This communication requires that the adapter trusts rancher's certificate.
28+
29+
The adapter supports 2 certificate setups: standard and private.
30+
31+
#### Standard Certificate Setup
32+
33+
If rancher is using a certificate provided by a trusted Certificate Authority (i.e. letsEncrypt) no additional setup is needed.
34+
35+
#### Private Certificate Setup
36+
37+
If rancher is using a self-generated certificate or a certificate signed by a private certificate authority, you will need to provide this certificate for the adapter.
38+
39+
First, extract the certificate into a file called `ca-additional.pem`. If you are using the rancher generated certs option, you can use the below command:
40+
41+
```bash
42+
kubectl get secret tls-rancher -n cattle-system -o jsonpath="{.data.tls\.crt}" | base64 -d >> ca-additional.pem
43+
```
44+
45+
Then, create the secret in the adapter namespace:
46+
47+
```bash
48+
kubectl -n cattle-csp-adapter-system create secret generic tls-ca-additional --from-file=ca-additional.pem
49+
```
50+
51+
As this certificate is rotated, you will need to replace the cert following the steps above, and then restart the adapter deployment, like below:
52+
53+
```bash
54+
kubectl rollout restart deploy/rancher-csp-adapter -n cattle-csp-adapter-system
55+
```
56+
57+
You can also use tools like certmanager's [trust operator](https://cert-manager.io/docs/projects/trust/) to automate this rotation. Keep in mind that this is not a supported option.
1858

1959
## CSP Background info
2060

charts/rancher-csp-adapter/templates/deployment.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,18 @@ spec:
2929
image: '{{ template "system_default_registry" . }}{{ .Values.image.repository }}:{{ .Values.image.tag }}'
3030
name: {{ .Chart.Name }}
3131
imagePullPolicy: "{{ .Values.image.imagePullPolicy }}"
32+
{{- if .Values.additionalTrustedCAs }}
33+
volumeMounts:
34+
- mountPath: /etc/ssl/certs/rancher-cert.pem
35+
name: tls-ca-volume
36+
subPath: ca-additional.pem
37+
readOnly: true
38+
{{- end }}
3239
serviceAccountName: {{ .Chart.Name }}
40+
{{- if .Values.additionalTrustedCAs }}
41+
volumes:
42+
- name: tls-ca-volume
43+
secret:
44+
defaultMode: 0444
45+
secretName: tls-ca-additional
46+
{{- end }}

charts/rancher-csp-adapter/values.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ global:
1111

1212
tolerations: []
1313

14+
# if rancher is using a privateCA, this certificate must be provided as a secret in the adapter's namespace - see the
15+
# readme/docs for more details
16+
#additionalTrustedCAs: true
17+
1418
# at least one csp must be enabled like below
1519
aws:
1620
enabled: false

package/Dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
FROM registry.suse.com/bci/bci-micro:15.3
2-
RUN mkdir -p supportconfig/rancher/
2+
3+
ARG user=adapter
4+
5+
RUN echo "$user:x:1000:1000::/home/$user:/bin/bash" >> /etc/passwd && \
6+
echo "$user:x:1000:" >> /etc/group && \
7+
mkdir /home/$user && \
8+
chown -R $user:$user /home/$user
9+
310
COPY bin/csp-adapter /usr/bin/
11+
12+
USER $user
13+
414
CMD ["csp-adapter"]

pkg/manager/aws.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ func (m *AWS) runComplianceCheck(ctx context.Context) error {
146146
if currentCheckoutInfo.EntitledLicenses == requiredLicenses {
147147
statusMessage = fmt.Sprintf("%s Rancher server has the required amount of licenses", statusPrefix)
148148
} else {
149-
statusMessage = fmt.Sprintf("%s You have exceeded your licensed node count. At least %d more licens(es) are required in AWS to become compliant.",
149+
statusMessage = fmt.Sprintf("%s You have exceeded your licensed node count. At least %d more license(s) are required in AWS to become compliant.",
150150
statusPrefix, requiredLicenses-currentCheckoutInfo.EntitledLicenses)
151151
}
152-
configMessage := fmt.Sprintf("Rancher server required %d licens(es) and was able to check out %d licens(es)", requiredLicenses, currentCheckoutInfo.EntitledLicenses)
152+
configMessage := fmt.Sprintf("Rancher server required %d license(s) and was able to check out %d license(s)", requiredLicenses, currentCheckoutInfo.EntitledLicenses)
153153

154154
return m.updateAdapterOutput(currentCheckoutInfo.EntitledLicenses == requiredLicenses, configMessage, statusMessage)
155155
}

pkg/metrics/scraper.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package metrics
22

33
import (
4-
"crypto/tls"
54
"fmt"
65
"net/http"
76
"strings"
@@ -22,14 +21,9 @@ type scraper struct {
2221
}
2322

2423
func NewScraper(rancherHost string, cfg *rest.Config) Scraper {
25-
tr := &http.Transport{
26-
TLSClientConfig: &tls.Config{
27-
InsecureSkipVerify: true,
28-
},
29-
}
3024
return &scraper{
3125
metricsURL: strings.Join([]string{"https://", rancherHost, "/metrics"}, ""),
32-
cli: &http.Client{Transport: tr},
26+
cli: &http.Client{},
3327
cfg: cfg,
3428
}
3529
}

0 commit comments

Comments
 (0)