-
Notifications
You must be signed in to change notification settings - Fork 165
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
Add CNB Service Bindings to Image and Build resources #371
Add CNB Service Bindings to Image and Build resources #371
Conversation
The CNB Service Bindings spec provides a structured way to expose service metadata and credentials into a build. For example, the build can use the binding information to install a database driver, configure an APM agent for the built image, or discover any other capability outside of the built container. Each binding reference has a name, a reference to a k8s ConfigMap holding service metadata, and optionally a k8s Secret holding service credentials. Builds generally should not have access to the credentials so that the values are not backed into the built image, but instead bound fresh at runtime. For images, the bindings are located at `.spec.build.bindings`: ``` kind: Image ... spec: ... build: bindings: - name: my-binding metadataRef: name: provider-binding-metadata secretRef: name: provider-binding-secret ``` For builds, the bindings are located at `.spec.bindings`: ``` kind: Build ... spec: ... bindings: - name: my-binding metadataRef: name: provider-binding-metadata secretRef: name: provider-binding-secret ``` In the build the bindings appear as a directory tree under the path specified by the `$CNB_BINDINGS` env var. Each binding is a directory, which in turn has a `metadata` directory with files and if credentials are exposed a `secret` directory with more files. The environment variable and volume mounts are available during the detect and build steps. Currently, the value of `$CNB_BINDINGS` is `/var/bindings` but should not be presumed to be stable or consistent with the value at runtime. There is no guarantee the same services, or types of services, will be bound at runtime. Refs buildpacks-community#369
Codecov Report
@@ Coverage Diff @@
## master #371 +/- ##
==========================================
+ Coverage 67.52% 68.26% +0.73%
==========================================
Files 81 81
Lines 3307 3409 +102
==========================================
+ Hits 2233 2327 +94
- Misses 800 805 +5
- Partials 274 277 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Thanks @scothis
There are questions that need to be further explored about the implications of supporting secret binding. Exposing the secret name would potentially expose an enumeration attack again other secrets in the namespace.
Used the validator to disable the secretRef on the binding until we have a better understanding of how to protect again secret enumeration attacks, or direct capturing of secrets if they know the name. |
This reverts commit 990504f.
Based on our conversation yesterday, I switch up the secret handling to forbid binding secrets that are attached to any service account in the namespace. This should offer a reasonable compromise to protect registry, and api server credentials while still allowing bindings to work as expected. Users who need more fine grain restrictions should look at applying a policy engine like OPA to make those access decisions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very excellent. Thanks @scothis !!
namespace: namespace, | ||
bindings: []v1alpha1.Binding{ | ||
{ | ||
Name: "naughty", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lolol
@@ -0,0 +1,64 @@ | |||
apiVersion: build.pivotal.io/v1alpha1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the samples!!!
pkg/apis/build/v1alpha1/build_pod.go
Outdated
@@ -110,6 +110,51 @@ func (b *Build) BuildPod(config BuildPodImages, secrets []corev1.Secret, bc Buil | |||
SubPath: b.Spec.Source.SubPath, // empty string is a nop | |||
} | |||
|
|||
bindingVolumes := []corev1.Volume{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be moved into a private method setupBindings()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎈 This is great! Thanks @scothis!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @scothis !!!
- #371 will list all service accounts on build create
- #371 will list all service accounts on build create
The CNB Service Bindings spec provides a structured way to expose
service metadata and credentials into a build. For example, the build
can use the binding information to install a database driver, configure
an APM agent for the built image, or discover any other capability
outside of the built container.
Each binding reference has a name, a reference to a k8s ConfigMap
holding service metadata, and optionally a k8s Secret holding service
credentials. Builds generally should not have access to the credentials
so that the values are not backed into the built image, but instead
bound fresh at runtime.
For images, the bindings are located at
.spec.build.bindings
:For builds, the bindings are located at
.spec.bindings
:In the build the bindings appear as a directory tree under the path
specified by the
$CNB_BINDINGS
env var. Each binding is a directory,which in turn has a
metadata
directory with files and if credentialsare exposed a
secret
directory with more files. The environmentvariable and volume mounts are available during the detect and build
steps. Currently, the value of
$CNB_BINDINGS
is/var/bindings
butshould not be presumed to be stable or consistent with the value at
runtime.
There is no guarantee the same services, or types of services, will be
bound at runtime.
Refs #369