Skip to content

Commit 11f2a5d

Browse files
authored
Merge pull request #312 from adborden/feature/pipe-step-credentials
feat: pass credential secrets from pipeline
2 parents 66e076e + d9462ab commit 11f2a5d

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,69 @@ spec:
276276
password: <password> # or KCL_SRC_PASSWORD environment variable
277277
```
278278

279+
You can provide credentials in a Secret to your pipeline step under the name `kcl-registry`.
280+
281+
```yaml
282+
# composition.yaml
283+
apiVersion: apiextensions.crossplane.io/v1
284+
kind: Composition
285+
metadata:
286+
name: example
287+
spec:
288+
compositeTypeRef:
289+
apiVersion: example.crossplane.io/v1beta1
290+
kind: XR
291+
mode: Pipeline
292+
pipeline:
293+
- step: basic
294+
functionRef:
295+
name: function-kcl
296+
input:
297+
apiVersion: krm.kcl.dev/v1alpha1
298+
kind: KCLInput
299+
source: |
300+
# Read the XR
301+
oxr = option("params").oxr
302+
# Patch the XR with the status field
303+
dxr = {
304+
**option("params").dxr
305+
status.dummy = "cool-status"
306+
}
307+
# Construct a bucket
308+
bucket = {
309+
apiVersion = "s3.aws.upbound.io/v1beta1"
310+
kind = "Bucket"
311+
metadata.annotations: {
312+
"krm.kcl.dev/composition-resource-name" = "bucket"
313+
}
314+
spec.forProvider.region = option("oxr").spec.region
315+
}
316+
# Return the bucket and patched XR
317+
items = [bucket, dxr]
318+
credentials: # If private OCI registry
319+
- name: kcl-registry
320+
source: Secret
321+
secretRef:
322+
namespace: default
323+
name: default
324+
```
325+
326+
And your secret:
327+
328+
```yaml
329+
apiVersion: v1
330+
kind: Secret
331+
metadata:
332+
name: default
333+
namsepace: default
334+
data:
335+
username: dXNlcm5hbWU=
336+
password: cGFzc3dvcmQ=
337+
url: aHR0cHM6Ly9leGFtcGxlLmNvbQ==
338+
```
339+
340+
You can use these credentials with `crossplane render --function-credentials=secret.yaml xr.yaml composition.yaml functions.yaml`.
341+
279342
### Run Config
280343

281344
```yaml

fn.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
6060
if f.dependencies != "" {
6161
in.Spec.Dependencies = f.dependencies + "\n" + in.Spec.Dependencies
6262
}
63+
// Add credentials
64+
if creds, ok := req.Credentials["kcl-registry"]; ok {
65+
data := creds.GetCredentialData()
66+
if data != nil {
67+
if password, ok := data.Data["password"]; ok {
68+
in.Spec.Credentials.Password = string(password)
69+
if username, ok := data.Data["username"]; ok {
70+
in.Spec.Credentials.Username = string(username)
71+
}
72+
if url, ok := data.Data["url"]; ok {
73+
in.Spec.Credentials.Url = string(url)
74+
}
75+
} else {
76+
log.Info("Warning: required password not found in the credentials")
77+
}
78+
}
79+
}
6380
if err := in.Validate(); err != nil {
6481
response.Fatal(rsp, errors.Wrap(err, "invalid function input"))
6582
return rsp, nil

0 commit comments

Comments
 (0)