...

Source file src/k8s.io/api/certificates/v1/types.go

Documentation: k8s.io/api/certificates/v1

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1
    18  
    19  import (
    20  	"fmt"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  )
    25  
    26  // +genclient
    27  // +genclient:nonNamespaced
    28  // +genclient:method=UpdateApproval,verb=update,subresource=approval,input=k8s.io/api/certificates/v1.CertificateSigningRequest,result=k8s.io/api/certificates/v1.CertificateSigningRequest
    29  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    30  
    31  // CertificateSigningRequest objects provide a mechanism to obtain x509 certificates
    32  // by submitting a certificate signing request, and having it asynchronously approved and issued.
    33  //
    34  // Kubelets use this API to obtain:
    35  //  1. client certificates to authenticate to kube-apiserver (with the "kubernetes.io/kube-apiserver-client-kubelet" signerName).
    36  //  2. serving certificates for TLS endpoints kube-apiserver can connect to securely (with the "kubernetes.io/kubelet-serving" signerName).
    37  //
    38  // This API can be used to request client certificates to authenticate to kube-apiserver
    39  // (with the "kubernetes.io/kube-apiserver-client" signerName),
    40  // or to obtain certificates from custom non-Kubernetes signers.
    41  type CertificateSigningRequest struct {
    42  	metav1.TypeMeta `json:",inline"`
    43  	// +optional
    44  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    45  
    46  	// spec contains the certificate request, and is immutable after creation.
    47  	// Only the request, signerName, expirationSeconds, and usages fields can be set on creation.
    48  	// Other fields are derived by Kubernetes and cannot be modified by users.
    49  	Spec CertificateSigningRequestSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
    50  
    51  	// status contains information about whether the request is approved or denied,
    52  	// and the certificate issued by the signer, or the failure condition indicating signer failure.
    53  	// +optional
    54  	Status CertificateSigningRequestStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
    55  }
    56  
    57  // CertificateSigningRequestSpec contains the certificate request.
    58  type CertificateSigningRequestSpec struct {
    59  	// request contains an x509 certificate signing request encoded in a "CERTIFICATE REQUEST" PEM block.
    60  	// When serialized as JSON or YAML, the data is additionally base64-encoded.
    61  	// +listType=atomic
    62  	Request []byte `json:"request" protobuf:"bytes,1,opt,name=request"`
    63  
    64  	// signerName indicates the requested signer, and is a qualified name.
    65  	//
    66  	// List/watch requests for CertificateSigningRequests can filter on this field using a "spec.signerName=NAME" fieldSelector.
    67  	//
    68  	// Well-known Kubernetes signers are:
    69  	//  1. "kubernetes.io/kube-apiserver-client": issues client certificates that can be used to authenticate to kube-apiserver.
    70  	//   Requests for this signer are never auto-approved by kube-controller-manager, can be issued by the "csrsigning" controller in kube-controller-manager.
    71  	//  2. "kubernetes.io/kube-apiserver-client-kubelet": issues client certificates that kubelets use to authenticate to kube-apiserver.
    72  	//   Requests for this signer can be auto-approved by the "csrapproving" controller in kube-controller-manager, and can be issued by the "csrsigning" controller in kube-controller-manager.
    73  	//  3. "kubernetes.io/kubelet-serving" issues serving certificates that kubelets use to serve TLS endpoints, which kube-apiserver can connect to securely.
    74  	//   Requests for this signer are never auto-approved by kube-controller-manager, and can be issued by the "csrsigning" controller in kube-controller-manager.
    75  	//
    76  	// More details are available at https://k8s.io/docs/reference/access-authn-authz/certificate-signing-requests/#kubernetes-signers
    77  	//
    78  	// Custom signerNames can also be specified. The signer defines:
    79  	//  1. Trust distribution: how trust (CA bundles) are distributed.
    80  	//  2. Permitted subjects: and behavior when a disallowed subject is requested.
    81  	//  3. Required, permitted, or forbidden x509 extensions in the request (including whether subjectAltNames are allowed, which types, restrictions on allowed values) and behavior when a disallowed extension is requested.
    82  	//  4. Required, permitted, or forbidden key usages / extended key usages.
    83  	//  5. Expiration/certificate lifetime: whether it is fixed by the signer, configurable by the admin.
    84  	//  6. Whether or not requests for CA certificates are allowed.
    85  	SignerName string `json:"signerName" protobuf:"bytes,7,opt,name=signerName"`
    86  
    87  	// expirationSeconds is the requested duration of validity of the issued
    88  	// certificate. The certificate signer may issue a certificate with a different
    89  	// validity duration so a client must check the delta between the notBefore and
    90  	// and notAfter fields in the issued certificate to determine the actual duration.
    91  	//
    92  	// The v1.22+ in-tree implementations of the well-known Kubernetes signers will
    93  	// honor this field as long as the requested duration is not greater than the
    94  	// maximum duration they will honor per the --cluster-signing-duration CLI
    95  	// flag to the Kubernetes controller manager.
    96  	//
    97  	// Certificate signers may not honor this field for various reasons:
    98  	//
    99  	//   1. Old signer that is unaware of the field (such as the in-tree
   100  	//      implementations prior to v1.22)
   101  	//   2. Signer whose configured maximum is shorter than the requested duration
   102  	//   3. Signer whose configured minimum is longer than the requested duration
   103  	//
   104  	// The minimum valid value for expirationSeconds is 600, i.e. 10 minutes.
   105  	//
   106  	// +optional
   107  	ExpirationSeconds *int32 `json:"expirationSeconds,omitempty" protobuf:"varint,8,opt,name=expirationSeconds"`
   108  
   109  	// usages specifies a set of key usages requested in the issued certificate.
   110  	//
   111  	// Requests for TLS client certificates typically request: "digital signature", "key encipherment", "client auth".
   112  	//
   113  	// Requests for TLS serving certificates typically request: "key encipherment", "digital signature", "server auth".
   114  	//
   115  	// Valid values are:
   116  	//  "signing", "digital signature", "content commitment",
   117  	//  "key encipherment", "key agreement", "data encipherment",
   118  	//  "cert sign", "crl sign", "encipher only", "decipher only", "any",
   119  	//  "server auth", "client auth",
   120  	//  "code signing", "email protection", "s/mime",
   121  	//  "ipsec end system", "ipsec tunnel", "ipsec user",
   122  	//  "timestamping", "ocsp signing", "microsoft sgc", "netscape sgc"
   123  	// +listType=atomic
   124  	Usages []KeyUsage `json:"usages,omitempty" protobuf:"bytes,5,opt,name=usages"`
   125  
   126  	// username contains the name of the user that created the CertificateSigningRequest.
   127  	// Populated by the API server on creation and immutable.
   128  	// +optional
   129  	Username string `json:"username,omitempty" protobuf:"bytes,2,opt,name=username"`
   130  	// uid contains the uid of the user that created the CertificateSigningRequest.
   131  	// Populated by the API server on creation and immutable.
   132  	// +optional
   133  	UID string `json:"uid,omitempty" protobuf:"bytes,3,opt,name=uid"`
   134  	// groups contains group membership of the user that created the CertificateSigningRequest.
   135  	// Populated by the API server on creation and immutable.
   136  	// +listType=atomic
   137  	// +optional
   138  	Groups []string `json:"groups,omitempty" protobuf:"bytes,4,rep,name=groups"`
   139  	// extra contains extra attributes of the user that created the CertificateSigningRequest.
   140  	// Populated by the API server on creation and immutable.
   141  	// +optional
   142  	Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,6,rep,name=extra"`
   143  }
   144  
   145  // Built in signerName values that are honored by kube-controller-manager.
   146  const (
   147  	// "kubernetes.io/kube-apiserver-client" signer issues client certificates that can be used to authenticate to kube-apiserver.
   148  	// Never auto-approved by kube-controller-manager.
   149  	// Can be issued by the "csrsigning" controller in kube-controller-manager.
   150  	KubeAPIServerClientSignerName = "kubernetes.io/kube-apiserver-client"
   151  
   152  	// "kubernetes.io/kube-apiserver-client-kubelet" issues client certificates that kubelets use to authenticate to kube-apiserver.
   153  	// Can be auto-approved by the "csrapproving" controller in kube-controller-manager.
   154  	// Can be issued by the "csrsigning" controller in kube-controller-manager.
   155  	KubeAPIServerClientKubeletSignerName = "kubernetes.io/kube-apiserver-client-kubelet"
   156  
   157  	// "kubernetes.io/kubelet-serving" issues serving certificates that kubelets use to serve TLS endpoints,
   158  	// which kube-apiserver can connect to securely.
   159  	// Never auto-approved by kube-controller-manager.
   160  	// Can be issued by the "csrsigning" controller in kube-controller-manager.
   161  	KubeletServingSignerName = "kubernetes.io/kubelet-serving"
   162  )
   163  
   164  // ExtraValue masks the value so protobuf can generate
   165  // +protobuf.nullable=true
   166  // +protobuf.options.(gogoproto.goproto_stringer)=false
   167  type ExtraValue []string
   168  
   169  func (t ExtraValue) String() string {
   170  	return fmt.Sprintf("%v", []string(t))
   171  }
   172  
   173  // CertificateSigningRequestStatus contains conditions used to indicate
   174  // approved/denied/failed status of the request, and the issued certificate.
   175  type CertificateSigningRequestStatus struct {
   176  	// conditions applied to the request. Known conditions are "Approved", "Denied", and "Failed".
   177  	// +listType=map
   178  	// +listMapKey=type
   179  	// +optional
   180  	Conditions []CertificateSigningRequestCondition `json:"conditions,omitempty" protobuf:"bytes,1,rep,name=conditions"`
   181  
   182  	// certificate is populated with an issued certificate by the signer after an Approved condition is present.
   183  	// This field is set via the /status subresource. Once populated, this field is immutable.
   184  	//
   185  	// If the certificate signing request is denied, a condition of type "Denied" is added and this field remains empty.
   186  	// If the signer cannot issue the certificate, a condition of type "Failed" is added and this field remains empty.
   187  	//
   188  	// Validation requirements:
   189  	//  1. certificate must contain one or more PEM blocks.
   190  	//  2. All PEM blocks must have the "CERTIFICATE" label, contain no headers, and the encoded data
   191  	//   must be a BER-encoded ASN.1 Certificate structure as described in section 4 of RFC5280.
   192  	//  3. Non-PEM content may appear before or after the "CERTIFICATE" PEM blocks and is unvalidated,
   193  	//   to allow for explanatory text as described in section 5.2 of RFC7468.
   194  	//
   195  	// If more than one PEM block is present, and the definition of the requested spec.signerName
   196  	// does not indicate otherwise, the first block is the issued certificate,
   197  	// and subsequent blocks should be treated as intermediate certificates and presented in TLS handshakes.
   198  	//
   199  	// The certificate is encoded in PEM format.
   200  	//
   201  	// When serialized as JSON or YAML, the data is additionally base64-encoded, so it consists of:
   202  	//
   203  	//     base64(
   204  	//     -----BEGIN CERTIFICATE-----
   205  	//     ...
   206  	//     -----END CERTIFICATE-----
   207  	//     )
   208  	//
   209  	// +listType=atomic
   210  	// +optional
   211  	Certificate []byte `json:"certificate,omitempty" protobuf:"bytes,2,opt,name=certificate"`
   212  }
   213  
   214  // RequestConditionType is the type of a CertificateSigningRequestCondition
   215  type RequestConditionType string
   216  
   217  // Well-known condition types for certificate requests.
   218  const (
   219  	// Approved indicates the request was approved and should be issued by the signer.
   220  	CertificateApproved RequestConditionType = "Approved"
   221  	// Denied indicates the request was denied and should not be issued by the signer.
   222  	CertificateDenied RequestConditionType = "Denied"
   223  	// Failed indicates the signer failed to issue the certificate.
   224  	CertificateFailed RequestConditionType = "Failed"
   225  )
   226  
   227  // CertificateSigningRequestCondition describes a condition of a CertificateSigningRequest object
   228  type CertificateSigningRequestCondition struct {
   229  	// type of the condition. Known conditions are "Approved", "Denied", and "Failed".
   230  	//
   231  	// An "Approved" condition is added via the /approval subresource,
   232  	// indicating the request was approved and should be issued by the signer.
   233  	//
   234  	// A "Denied" condition is added via the /approval subresource,
   235  	// indicating the request was denied and should not be issued by the signer.
   236  	//
   237  	// A "Failed" condition is added via the /status subresource,
   238  	// indicating the signer failed to issue the certificate.
   239  	//
   240  	// Approved and Denied conditions are mutually exclusive.
   241  	// Approved, Denied, and Failed conditions cannot be removed once added.
   242  	//
   243  	// Only one condition of a given type is allowed.
   244  	Type RequestConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=RequestConditionType"`
   245  	// status of the condition, one of True, False, Unknown.
   246  	// Approved, Denied, and Failed conditions may not be "False" or "Unknown".
   247  	Status v1.ConditionStatus `json:"status" protobuf:"bytes,6,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"`
   248  	// reason indicates a brief reason for the request state
   249  	// +optional
   250  	Reason string `json:"reason,omitempty" protobuf:"bytes,2,opt,name=reason"`
   251  	// message contains a human readable message with details about the request state
   252  	// +optional
   253  	Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
   254  	// lastUpdateTime is the time of the last update to this condition
   255  	// +optional
   256  	LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,4,opt,name=lastUpdateTime"`
   257  	// lastTransitionTime is the time the condition last transitioned from one status to another.
   258  	// If unset, when a new condition type is added or an existing condition's status is changed,
   259  	// the server defaults this to the current time.
   260  	// +optional
   261  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,5,opt,name=lastTransitionTime"`
   262  }
   263  
   264  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   265  
   266  // CertificateSigningRequestList is a collection of CertificateSigningRequest objects
   267  type CertificateSigningRequestList struct {
   268  	metav1.TypeMeta `json:",inline"`
   269  	// +optional
   270  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   271  
   272  	// items is a collection of CertificateSigningRequest objects
   273  	Items []CertificateSigningRequest `json:"items" protobuf:"bytes,2,rep,name=items"`
   274  }
   275  
   276  // KeyUsage specifies valid usage contexts for keys.
   277  // See:
   278  //
   279  //	https://tools.ietf.org/html/rfc5280#section-4.2.1.3
   280  //	https://tools.ietf.org/html/rfc5280#section-4.2.1.12
   281  //
   282  // +enum
   283  type KeyUsage string
   284  
   285  // Valid key usages
   286  const (
   287  	UsageSigning           KeyUsage = "signing"
   288  	UsageDigitalSignature  KeyUsage = "digital signature"
   289  	UsageContentCommitment KeyUsage = "content commitment"
   290  	UsageKeyEncipherment   KeyUsage = "key encipherment"
   291  	UsageKeyAgreement      KeyUsage = "key agreement"
   292  	UsageDataEncipherment  KeyUsage = "data encipherment"
   293  	UsageCertSign          KeyUsage = "cert sign"
   294  	UsageCRLSign           KeyUsage = "crl sign"
   295  	UsageEncipherOnly      KeyUsage = "encipher only"
   296  	UsageDecipherOnly      KeyUsage = "decipher only"
   297  	UsageAny               KeyUsage = "any"
   298  	UsageServerAuth        KeyUsage = "server auth"
   299  	UsageClientAuth        KeyUsage = "client auth"
   300  	UsageCodeSigning       KeyUsage = "code signing"
   301  	UsageEmailProtection   KeyUsage = "email protection"
   302  	UsageSMIME             KeyUsage = "s/mime"
   303  	UsageIPsecEndSystem    KeyUsage = "ipsec end system"
   304  	UsageIPsecTunnel       KeyUsage = "ipsec tunnel"
   305  	UsageIPsecUser         KeyUsage = "ipsec user"
   306  	UsageTimestamping      KeyUsage = "timestamping"
   307  	UsageOCSPSigning       KeyUsage = "ocsp signing"
   308  	UsageMicrosoftSGC      KeyUsage = "microsoft sgc"
   309  	UsageNetscapeSGC       KeyUsage = "netscape sgc"
   310  )
   311  

View as plain text