Skip to content
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

Secrets fixups #4653

Merged
merged 3 commits into from
Feb 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/design/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ type Secret struct {
ObjectMeta

// Data contains the secret data. Each key must be a valid DNS_SUBDOMAIN.
// The serialized form of the secret data is a base64 encoded string.
// The serialized form of the secret data is a base64 encoded string,
// representing the arbitrary (possibly non-string) data value here.
Data map[string][]byte `json:"data,omitempty"`

// Used to facilitate programatic handling of secret data.
Expand All @@ -283,9 +284,9 @@ type Secret struct {
type SecretType string

const (
SecretTypeOpaque SecretType = "opaque" // Opaque (arbitrary data; default)
SecretTypeKubernetesAuthToken SecretType = "kubernetes-auth" // Kubernetes auth token
SecretTypeDockerRegistryAuth SecretType = "docker-reg-auth" // Docker registry auth
SecretTypeOpaque SecretType = "Opaque" // Opaque (arbitrary data; default)
SecretTypeKubernetesAuthToken SecretType = "KubernetesAuth" // Kubernetes auth token
SecretTypeDockerRegistryAuth SecretType = "DockerRegistryAuth" // Docker registry auth
// FUTURE: other type values
)

Expand Down Expand Up @@ -398,8 +399,9 @@ To create a pod that uses an ssh key stored as a secret, we first need to create
}
```

**Note:** The values of secret data are encoded as base64-encoded strings. Newlines are not
valid within these strings and must be omitted.
**Note:** The serialized JSON and YAML values of secret data are encoded as
base64 strings. Newlines are not valid within these strings and must be
omitted.

Now we can create a pod which references the secret with the ssh key and consumes it in a volume:

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
func(vs *api.VolumeSource, c fuzz.Continue) {
// Exactly one of the fields should be set.
//FIXME: the fuzz can still end up nil. What if fuzz allowed me to say that?
fuzzOneOf(c, &vs.HostPath, &vs.EmptyDir, &vs.GCEPersistentDisk, &vs.GitRepo)
fuzzOneOf(c, &vs.HostPath, &vs.EmptyDir, &vs.GCEPersistentDisk, &vs.GitRepo, &vs.Secret)
},
func(d *api.DNSPolicy, c fuzz.Continue) {
policies := []api.DNSPolicy{api.DNSClusterFirst, api.DNSDefault}
Expand Down Expand Up @@ -233,6 +233,7 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
c.Fuzz(&s.ObjectMeta)

s.Type = api.SecretTypeOpaque
c.Fuzz(&s.Data)
},
func(ep *api.Endpoint, c fuzz.Continue) {
// TODO: If our API used a particular type for IP fields we could just catch that here.
Expand Down
33 changes: 17 additions & 16 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,24 @@ type VolumeSource struct {
// machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and who can/can not
// mount host directories as read/write.
HostPath *HostPath `json:"hostPath"`
HostPath *HostPathVolumeSource `json:"hostPath"`
// EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDir *EmptyDir `json:"emptyDir"`
EmptyDir *EmptyDirVolumeSource `json:"emptyDir"`
// GCEPersistentDisk represents a GCE Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
GCEPersistentDisk *GCEPersistentDisk `json:"persistentDisk"`
GCEPersistentDisk *GCEPersistentDiskVolumeSource `json:"persistentDisk"`
// GitRepo represents a git repository at a particular revision.
GitRepo *GitRepo `json:"gitRepo"`
GitRepo *GitRepoVolumeSource `json:"gitRepo"`
// Secret represents a secret that should populate this volume.
Secret *SecretSource `json:"secret"`
Secret *SecretVolumeSource `json:"secret"`
}

// HostPath represents bare host directory volume.
type HostPath struct {
// HostPathVolumeSource represents bare host directory volume.
type HostPathVolumeSource struct {
Path string `json:"path"`
}

type EmptyDir struct{}
type EmptyDirVolumeSource struct{}

// Protocol defines network protocols supported for things like conatiner ports.
type Protocol string
Expand All @@ -199,12 +199,12 @@ const (
ProtocolUDP Protocol = "UDP"
)

// GCEPersistentDisk represents a Persistent Disk resource in Google Compute Engine.
// GCEPersistentDiskVolumeSource represents a Persistent Disk resource in Google Compute Engine.
//
// A GCE PD must exist and be formatted before mounting to a container.
// The disk must also be in the same GCE project and zone as the kubelet.
// A GCE PD can only be mounted as read/write once.
type GCEPersistentDisk struct {
type GCEPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in GCE
PDName string `json:"pdName"`
// Required: Filesystem type to mount.
Expand All @@ -221,20 +221,20 @@ type GCEPersistentDisk struct {
ReadOnly bool `json:"readOnly,omitempty"`
}

// GitRepo represents a volume that is pulled from git when the pod is created.
type GitRepo struct {
// GitRepoVolumeSource represents a volume that is pulled from git when the pod is created.
type GitRepoVolumeSource struct {
// Repository URL
Repository string `json:"repository"`
// Commit hash, this is optional
Revision string `json:"revision"`
// TODO: Consider credentials here.
}

// Adapts a Secret into a VolumeSource.
// SecretVolumeSource adapts a Secret into a VolumeSource.
//
// The contents of the target Secret's Data field will be presented in a volume
// as files using the keys in the Data field as the file names.
type SecretSource struct {
type SecretVolumeSource struct {
// Reference to a Secret
Target ObjectReference `json:"target"`
}
Expand Down Expand Up @@ -1330,7 +1330,8 @@ type Secret struct {
ObjectMeta `json:"metadata,omitempty"`

// Data contains the secret data. Each key must be a valid DNS_SUBDOMAIN.
// The serialized form of the secret data is a base64 encoded string.
// The serialized form of the secret data is a base64 encoded string,
// representing the arbitrary (possibly non-string) data value here.
Data map[string][]byte `json:"data,omitempty"`

// Used to facilitate programatic handling of secret data.
Expand All @@ -1342,7 +1343,7 @@ const MaxSecretSize = 1 * 1024 * 1024
type SecretType string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgrant0607 wanted this renamed to SecretKind and for it to come before the Data field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in next push


const (
SecretTypeOpaque SecretType = "opaque" // Default; arbitrary user-defined data
SecretTypeOpaque SecretType = "Opaque" // Default; arbitrary user-defined data
)

type SecretList struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
func(obj *Volume) {
if util.AllPtrFieldsNil(&obj.Source) {
obj.Source = VolumeSource{
EmptyDir: &EmptyDir{},
EmptyDir: &EmptyDirVolumeSource{},
}
}
},
Expand Down
33 changes: 17 additions & 16 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ type VolumeSource struct {
// things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and
// who can/can not mount host directories as read/write.
HostDir *HostPath `json:"hostDir" description:"pre-existing host file or directory; generally for privileged system daemons or other agents tied to the host"`
HostDir *HostPathVolumeSource `json:"hostDir" description:"pre-existing host file or directory; generally for privileged system daemons or other agents tied to the host"`
// EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDir *EmptyDir `json:"emptyDir" description:"temporary directory that shares a pod's lifetime"`
EmptyDir *EmptyDirVolumeSource `json:"emptyDir" description:"temporary directory that shares a pod's lifetime"`
// GCEPersistentDisk represents a GCE Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
GCEPersistentDisk *GCEPersistentDisk `json:"persistentDisk" description:"GCE disk resource attached to the host machine on demand"`
GCEPersistentDisk *GCEPersistentDiskVolumeSource `json:"persistentDisk" description:"GCE disk resource attached to the host machine on demand"`
// GitRepo represents a git repository at a particular revision.
GitRepo *GitRepo `json:"gitRepo" description:"git repository at a particular revision"`
GitRepo *GitRepoVolumeSource `json:"gitRepo" description:"git repository at a particular revision"`
// Secret represents a secret to populate the volume with
Secret *SecretSource `json:"secret" description:"secret to populate volume with"`
Secret *SecretVolumeSource `json:"secret" description:"secret to populate volume with"`
}

// HostPath represents bare host directory volume.
type HostPath struct {
// HostPathVolumeSource represents bare host directory volume.
type HostPathVolumeSource struct {
Path string `json:"path" description:"path of the directory on the host"`
}

type EmptyDir struct{}
type EmptyDirVolumeSource struct{}

// Protocol defines network protocols supported for things like conatiner ports.
type Protocol string
Expand All @@ -124,12 +124,12 @@ const (
ProtocolUDP Protocol = "UDP"
)

// GCEPersistentDisk represents a Persistent Disk resource in Google Compute Engine.
// GCEPersistentDiskVolumeSource represents a Persistent Disk resource in Google Compute Engine.
//
// A GCE PD must exist and be formatted before mounting to a container.
// The disk must also be in the same GCE project and zone as the kubelet.
// A GCE PD can only be mounted as read/write once.
type GCEPersistentDisk struct {
type GCEPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in GCE
PDName string `json:"pdName" description:"unique name of the PD resource in GCE"`
// Required: Filesystem type to mount.
Expand All @@ -147,16 +147,16 @@ type GCEPersistentDisk struct {
ReadOnly bool `json:"readOnly,omitempty" description:"read-only if true, read-write otherwise (false or unspecified)"`
}

// GitRepo represents a volume that is pulled from git when the pod is created.
type GitRepo struct {
// GitRepoVolumeSource represents a volume that is pulled from git when the pod is created.
type GitRepoVolumeSource struct {
// Repository URL
Repository string `json:"repository" description:"repository URL"`
// Commit hash, this is optional
Revision string `json:"revision" description:"commit hash for the specified revision"`
}

// Adapts a Secret into a VolumeSource
type SecretSource struct {
// SecretVolumeSource adapts a Secret into a VolumeSource
type SecretVolumeSource struct {
// Reference to a Secret
Target ObjectReference `json:"target" description:"target is a reference to a secret"`
}
Expand Down Expand Up @@ -1113,7 +1113,8 @@ type Secret struct {
TypeMeta `json:",inline"`

// Data contains the secret data. Each key must be a valid DNS_SUBDOMAIN.
// The serialized form of the secret data is a base64 encoded string.
// The serialized form of the secret data is a base64 encoded string,
// representing the arbitrary (possibly non-string) data value here.
Data map[string][]byte `json:"data,omitempty" description:"data contains the secret data. Each key must be a valid DNS_SUBDOMAIN. Each value must be a base64 encoded string"`

// Used to facilitate programatic handling of secret data.
Expand All @@ -1125,7 +1126,7 @@ const MaxSecretSize = 1 * 1024 * 1024
type SecretType string

const (
SecretTypeOpaque SecretType = "opaque" // Default; arbitrary user-defined data
SecretTypeOpaque SecretType = "Opaque" // Default; arbitrary user-defined data
)

type SecretList struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
if util.AllPtrFieldsNil(&obj.Source) {
glog.Errorf("Defaulting volume source for %v", obj)
obj.Source = VolumeSource{
EmptyDir: &EmptyDir{},
EmptyDir: &EmptyDirVolumeSource{},
}
}
},
Expand Down
33 changes: 17 additions & 16 deletions pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ type VolumeSource struct {
// things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and
// who can/can not mount host directories as read/write.
HostDir *HostPath `json:"hostDir" description:"pre-existing host file or directory; generally for privileged system daemons or other agents tied to the host"`
HostDir *HostPathVolumeSource `json:"hostDir" description:"pre-existing host file or directory; generally for privileged system daemons or other agents tied to the host"`
// EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDir *EmptyDir `json:"emptyDir" description:"temporary directory that shares a pod's lifetime"`
EmptyDir *EmptyDirVolumeSource `json:"emptyDir" description:"temporary directory that shares a pod's lifetime"`
// A persistent disk that is mounted to the
// kubelet's host machine and then exposed to the pod.
GCEPersistentDisk *GCEPersistentDisk `json:"persistentDisk" description:"GCE disk resource attached to the host machine on demand"`
GCEPersistentDisk *GCEPersistentDiskVolumeSource `json:"persistentDisk" description:"GCE disk resource attached to the host machine on demand"`
// GitRepo represents a git repository at a particular revision.
GitRepo *GitRepo `json:"gitRepo" description:"git repository at a particular revision"`
GitRepo *GitRepoVolumeSource `json:"gitRepo" description:"git repository at a particular revision"`
// Secret is a secret to populate the volume with
Secret *SecretSource `json:"secret" description:"secret to populate volume"`
Secret *SecretVolumeSource `json:"secret" description:"secret to populate volume"`
}

// HostPath represents bare host directory volume.
type HostPath struct {
// HostPathVolumeSource represents bare host directory volume.
type HostPathVolumeSource struct {
Path string `json:"path" description:"path of the directory on the host"`
}

type EmptyDir struct{}
type EmptyDirVolumeSource struct{}

// Adapts a Secret into a VolumeSource
type SecretSource struct {
// SecretVolumeSource adapts a Secret into a VolumeSource
type SecretVolumeSource struct {
// Reference to a Secret
Target ObjectReference `json:"target" description:"target is a reference to a secret"`
}
Expand Down Expand Up @@ -114,12 +114,12 @@ type Port struct {
HostIP string `json:"hostIP,omitempty" description:"host IP to bind the port to"`
}

// GCEPersistentDisk represents a Persistent Disk resource in Google Compute Engine.
// GCEPersistentDiskVolumeSource represents a Persistent Disk resource in Google Compute Engine.
//
// A GCE PD must exist and be formatted before mounting to a container.
// The disk must also be in the same GCE project and zone as the kubelet.
// A GCE PD can only be mounted as read/write once.
type GCEPersistentDisk struct {
type GCEPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in GCE
PDName string `json:"pdName" description:"unique name of the PD resource in GCE"`
// Required: Filesystem type to mount.
Expand All @@ -137,8 +137,8 @@ type GCEPersistentDisk struct {
ReadOnly bool `json:"readOnly,omitempty" description:"read-only if true, read-write otherwise (false or unspecified)"`
}

// GitRepo represents a volume that is pulled from git when the pod is created.
type GitRepo struct {
// GitRepoVolumeSource represents a volume that is pulled from git when the pod is created.
type GitRepoVolumeSource struct {
// Repository URL
Repository string `json:"repository" description:"repository URL"`
// Commit hash, this is optional
Expand Down Expand Up @@ -1116,7 +1116,8 @@ type Secret struct {
TypeMeta `json:",inline"`

// Data contains the secret data. Each key must be a valid DNS_SUBDOMAIN.
// The serialized form of the secret data is a base64 encoded string.
// The serialized form of the secret data is a base64 encoded string,
// representing the arbitrary (possibly non-string) data value here.
Data map[string][]byte `json:"data,omitempty" description:"data contains the secret data. Each key must be a valid DNS_SUBDOMAIN. Each value must be a base64 encoded string"`

// Used to facilitate programatic handling of secret data.
Expand All @@ -1128,7 +1129,7 @@ const MaxSecretSize = 1 * 1024 * 1024
type SecretType string

const (
SecretTypeOpaque SecretType = "opaque" // Default; arbitrary user-defined data
SecretTypeOpaque SecretType = "Opaque" // Default; arbitrary user-defined data
)

type SecretList struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta3/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
func(obj *Volume) {
if util.AllPtrFieldsNil(&obj.Source) {
obj.Source = VolumeSource{
EmptyDir: &EmptyDir{},
EmptyDir: &EmptyDirVolumeSource{},
}
}
},
Expand Down