@@ -8,10 +8,13 @@ import (
8
8
"regexp"
9
9
"time"
10
10
11
- "github.com/golang/protobuf/ptypes"
12
- pb "github.com/linkerd/linkerd2/controller/gen/config"
11
+ corev1 "k8s.io/api/core/v1"
12
+ "k8s.io/client-go/kubernetes"
13
+
13
14
"github.com/linkerd/linkerd2/pkg/charts/linkerd2"
15
+ charts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
14
16
"github.com/linkerd/linkerd2/pkg/healthcheck"
17
+ "github.com/linkerd/linkerd2/pkg/issuercerts"
15
18
"github.com/linkerd/linkerd2/pkg/k8s"
16
19
"github.com/linkerd/linkerd2/pkg/version"
17
20
"github.com/spf13/cobra"
@@ -127,16 +130,16 @@ func repair(ctx context.Context, forced bool) error {
127
130
if err != nil {
128
131
return fmt .Errorf ("Failed to parse IssuanceLifetime from linkerd-config: %s" , err )
129
132
}
130
- idCtx := pb. IdentityContext {
131
- TrustAnchorsPem : values .IdentityTrustAnchorsPEM ,
132
- Scheme : values .Identity .Issuer .Scheme ,
133
- ClockSkewAllowance : ptypes . DurationProto ( clockSkewDuration ) ,
134
- IssuanceLifetime : ptypes . DurationProto ( issuanceLifetime ) ,
135
- TrustDomain : values .IdentityTrustDomain ,
133
+ idCtx := identityContext {
134
+ trustAnchorsPem : values .IdentityTrustAnchorsPEM ,
135
+ scheme : values .Identity .Issuer .Scheme ,
136
+ clockSkewAllowance : clockSkewDuration ,
137
+ issuanceLifetime : issuanceLifetime ,
138
+ trustDomain : values .IdentityTrustDomain ,
136
139
}
137
140
138
141
// Populate identity values
139
- err = fetchIdentityValues (ctx , k8sAPI , & idCtx , & values )
142
+ err = fetchIdentityValues (ctx , k8sAPI , idCtx , & values )
140
143
if err != nil {
141
144
return fmt .Errorf ("Failed to load issuer credentials: %s" , err )
142
145
}
@@ -185,3 +188,68 @@ func resetVersion(values *linkerd2.Values) error {
185
188
values .LinkerdVersion = defaults .LinkerdVersion
186
189
return nil
187
190
}
191
+
192
+ type identityContext struct {
193
+ trustAnchorsPem string
194
+ scheme string
195
+ clockSkewAllowance time.Duration
196
+ issuanceLifetime time.Duration
197
+ trustDomain string
198
+ }
199
+
200
+ // fetchIdentityValue checks the kubernetes API to fetch an existing
201
+ // linkerd identity configuration.
202
+ //
203
+ // This bypasses the public API so that we can access secrets and validate
204
+ // permissions.
205
+ func fetchIdentityValues (ctx context.Context , k kubernetes.Interface , idctx identityContext , values * charts.Values ) error {
206
+ if idctx .scheme == "" {
207
+ // if this is empty, then we are upgrading from a version
208
+ // that did not support issuer schemes. Just default to the
209
+ // linkerd one.
210
+ idctx .scheme = k8s .IdentityIssuerSchemeLinkerd
211
+ }
212
+
213
+ var trustAnchorsPEM string
214
+ var issuerData * issuercerts.IssuerCertData
215
+ var err error
216
+
217
+ trustAnchorsPEM = idctx .trustAnchorsPem
218
+
219
+ issuerData , err = fetchIssuer (ctx , k , trustAnchorsPEM , idctx .scheme )
220
+ if err != nil {
221
+ return err
222
+ }
223
+
224
+ values .IdentityTrustAnchorsPEM = trustAnchorsPEM
225
+ values .Identity .Issuer .Scheme = idctx .scheme
226
+ values .Identity .Issuer .ClockSkewAllowance = idctx .clockSkewAllowance .String ()
227
+ values .Identity .Issuer .IssuanceLifetime = idctx .issuanceLifetime .String ()
228
+ values .Identity .Issuer .TLS .KeyPEM = issuerData .IssuerKey
229
+ values .Identity .Issuer .TLS .CrtPEM = issuerData .IssuerCrt
230
+
231
+ return nil
232
+ }
233
+
234
+ func fetchIssuer (ctx context.Context , k kubernetes.Interface , trustPEM string , scheme string ) (* issuercerts.IssuerCertData , error ) {
235
+ var (
236
+ issuerData * issuercerts.IssuerCertData
237
+ err error
238
+ )
239
+ switch scheme {
240
+ case string (corev1 .SecretTypeTLS ):
241
+ // Do not return external issuer certs as no need of storing them in config and upgrade secrets
242
+ // Also contradicts condition in https://github.com/linkerd/linkerd2/blob/main/cli/cmd/options.go#L550
243
+ return & issuercerts.IssuerCertData {}, nil
244
+ default :
245
+ issuerData , err = issuercerts .FetchIssuerData (ctx , k , trustPEM , controlPlaneNamespace )
246
+ if issuerData != nil && issuerData .TrustAnchors != trustPEM {
247
+ issuerData .TrustAnchors = trustPEM
248
+ }
249
+ }
250
+ if err != nil {
251
+ return nil , err
252
+ }
253
+
254
+ return issuerData , nil
255
+ }
0 commit comments