Skip to content

Commit 1ae847b

Browse files
authored
Merge pull request #33 from starbops/fix-4511
fix(certs): auto-install ca retrieved from rancher
2 parents 07e84b1 + 951e368 commit 1ae847b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

pkg/cacerts/cacerts.go

+24
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/rancher/rancherd/pkg/tpm"
18+
"github.com/rancher/system-agent/pkg/applyinator"
1819
"github.com/rancher/wrangler/pkg/randomtoken"
1920
)
2021

@@ -161,6 +162,29 @@ func CACerts(server, token string, clusterToken bool) ([]byte, string, error) {
161162
return data, hashHex(data), nil
162163
}
163164

165+
func ToUpdateCACertificatesInstruction() (*applyinator.Instruction, error) {
166+
cmd := "update-ca-certificates"
167+
168+
return &applyinator.Instruction{
169+
Name: "update-ca-certificates",
170+
SaveOutput: true,
171+
Command: cmd,
172+
}, nil
173+
}
174+
175+
func ToFile(server, token string) (*applyinator.File, error) {
176+
cacert, _, err := CACerts(server, token, true)
177+
if err != nil {
178+
return nil, err
179+
}
180+
181+
return &applyinator.File{
182+
Content: base64.StdEncoding.EncodeToString(cacert),
183+
Path: "/etc/pki/trust/anchors/embedded-rancher-ca.pem",
184+
Permissions: "0644",
185+
}, nil
186+
}
187+
164188
func hashHex(token []byte) string {
165189
hash := sha256.Sum256(token)
166190
return hex.EncodeToString(hash[:])

pkg/plan/bootstrap.go

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/rancher/system-agent/pkg/applyinator"
88

9+
"github.com/rancher/rancherd/pkg/cacerts"
910
"github.com/rancher/rancherd/pkg/config"
1011
"github.com/rancher/rancherd/pkg/discovery"
1112
"github.com/rancher/rancherd/pkg/join"
@@ -50,9 +51,15 @@ func toJoinPlan(cfg *config.Config, dataDir string) (*applyinator.Plan, error) {
5051
}
5152

5253
plan := plan{}
54+
if err := plan.addFile(cacerts.ToFile(cfg.Server, cfg.Token)); err != nil {
55+
return nil, err
56+
}
5357
if err := plan.addFile(join.ToScriptFile(cfg, dataDir)); err != nil {
5458
return nil, err
5559
}
60+
if err := plan.addInstruction(cacerts.ToUpdateCACertificatesInstruction()); err != nil {
61+
return nil, err
62+
}
5663
if err := plan.addInstruction(join.ToInstruction(cfg, dataDir)); err != nil {
5764
return nil, err
5865
}
@@ -202,6 +209,7 @@ func (p *plan) addFiles(cfg *config.Config, dataDir string) error {
202209

203210
// rancher values.yaml
204211
return p.addFile(rancher.ToFile(cfg, dataDir))
212+
205213
}
206214

207215
func (p *plan) addFile(file *applyinator.File, err error) error {

pkg/rancher/wait.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ToWaitSUCInstruction(imageOverride, systemDefaultRegistry, k8sVersion strin
4444
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
4545
}
4646
return &applyinator.Instruction{
47-
Name: "wait-rancher-webhook",
47+
Name: "wait-system-upgrade-controller",
4848
SaveOutput: true,
4949
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "cattle-system", "rollout", "status", "-w", "deploy/system-upgrade-controller"},
5050
Env: kubectl.Env(k8sVersion),

0 commit comments

Comments
 (0)