options.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package policy
  2. // Options is a container for authority level x509 and SSH
  3. // policy configuration.
  4. type Options struct {
  5. X509 *X509PolicyOptions `json:"x509,omitempty"`
  6. SSH *SSHPolicyOptions `json:"ssh,omitempty"`
  7. }
  8. // GetX509Options returns the x509 authority level policy
  9. // configuration
  10. func (o *Options) GetX509Options() *X509PolicyOptions {
  11. if o == nil {
  12. return nil
  13. }
  14. return o.X509
  15. }
  16. // GetSSHOptions returns the SSH authority level policy
  17. // configuration
  18. func (o *Options) GetSSHOptions() *SSHPolicyOptions {
  19. if o == nil {
  20. return nil
  21. }
  22. return o.SSH
  23. }
  24. // X509PolicyOptionsInterface is an interface for providers
  25. // of x509 allowed and denied names.
  26. type X509PolicyOptionsInterface interface {
  27. GetAllowedNameOptions() *X509NameOptions
  28. GetDeniedNameOptions() *X509NameOptions
  29. AreWildcardNamesAllowed() bool
  30. }
  31. // X509PolicyOptions is a container for x509 allowed and denied
  32. // names.
  33. type X509PolicyOptions struct {
  34. // AllowedNames contains the x509 allowed names
  35. AllowedNames *X509NameOptions `json:"allow,omitempty"`
  36. // DeniedNames contains the x509 denied names
  37. DeniedNames *X509NameOptions `json:"deny,omitempty"`
  38. // AllowWildcardNames indicates if literal wildcard names
  39. // like *.example.com are allowed. Defaults to false.
  40. AllowWildcardNames bool `json:"allowWildcardNames,omitempty"`
  41. }
  42. // X509NameOptions models the X509 name policy configuration.
  43. type X509NameOptions struct {
  44. CommonNames []string `json:"cn,omitempty"`
  45. DNSDomains []string `json:"dns,omitempty"`
  46. IPRanges []string `json:"ip,omitempty"`
  47. EmailAddresses []string `json:"email,omitempty"`
  48. URIDomains []string `json:"uri,omitempty"`
  49. }
  50. // HasNames checks if the AllowedNameOptions has one or more
  51. // names configured.
  52. func (o *X509NameOptions) HasNames() bool {
  53. return len(o.CommonNames) > 0 ||
  54. len(o.DNSDomains) > 0 ||
  55. len(o.IPRanges) > 0 ||
  56. len(o.EmailAddresses) > 0 ||
  57. len(o.URIDomains) > 0
  58. }
  59. // GetAllowedNameOptions returns x509 allowed name policy configuration
  60. func (o *X509PolicyOptions) GetAllowedNameOptions() *X509NameOptions {
  61. if o == nil {
  62. return nil
  63. }
  64. return o.AllowedNames
  65. }
  66. // GetDeniedNameOptions returns the x509 denied name policy configuration
  67. func (o *X509PolicyOptions) GetDeniedNameOptions() *X509NameOptions {
  68. if o == nil {
  69. return nil
  70. }
  71. return o.DeniedNames
  72. }
  73. // AreWildcardNamesAllowed returns whether the authority allows
  74. // literal wildcard names to be signed.
  75. func (o *X509PolicyOptions) AreWildcardNamesAllowed() bool {
  76. if o == nil {
  77. return true
  78. }
  79. return o.AllowWildcardNames
  80. }
  81. // SSHPolicyOptionsInterface is an interface for providers of
  82. // SSH user and host name policy configuration.
  83. type SSHPolicyOptionsInterface interface {
  84. GetAllowedUserNameOptions() *SSHNameOptions
  85. GetDeniedUserNameOptions() *SSHNameOptions
  86. GetAllowedHostNameOptions() *SSHNameOptions
  87. GetDeniedHostNameOptions() *SSHNameOptions
  88. }
  89. // SSHPolicyOptions is a container for SSH user and host policy
  90. // configuration
  91. type SSHPolicyOptions struct {
  92. // User contains SSH user certificate options.
  93. User *SSHUserCertificateOptions `json:"user,omitempty"`
  94. // Host contains SSH host certificate options.
  95. Host *SSHHostCertificateOptions `json:"host,omitempty"`
  96. }
  97. // GetAllowedUserNameOptions returns the SSH allowed user name policy
  98. // configuration.
  99. func (o *SSHPolicyOptions) GetAllowedUserNameOptions() *SSHNameOptions {
  100. if o == nil || o.User == nil {
  101. return nil
  102. }
  103. return o.User.AllowedNames
  104. }
  105. // GetDeniedUserNameOptions returns the SSH denied user name policy
  106. // configuration.
  107. func (o *SSHPolicyOptions) GetDeniedUserNameOptions() *SSHNameOptions {
  108. if o == nil || o.User == nil {
  109. return nil
  110. }
  111. return o.User.DeniedNames
  112. }
  113. // GetAllowedHostNameOptions returns the SSH allowed host name policy
  114. // configuration.
  115. func (o *SSHPolicyOptions) GetAllowedHostNameOptions() *SSHNameOptions {
  116. if o == nil || o.Host == nil {
  117. return nil
  118. }
  119. return o.Host.AllowedNames
  120. }
  121. // GetDeniedHostNameOptions returns the SSH denied host name policy
  122. // configuration.
  123. func (o *SSHPolicyOptions) GetDeniedHostNameOptions() *SSHNameOptions {
  124. if o == nil || o.Host == nil {
  125. return nil
  126. }
  127. return o.Host.DeniedNames
  128. }
  129. // SSHUserCertificateOptions is a collection of SSH user certificate options.
  130. type SSHUserCertificateOptions struct {
  131. // AllowedNames contains the names the provisioner is authorized to sign
  132. AllowedNames *SSHNameOptions `json:"allow,omitempty"`
  133. // DeniedNames contains the names the provisioner is not authorized to sign
  134. DeniedNames *SSHNameOptions `json:"deny,omitempty"`
  135. }
  136. // SSHHostCertificateOptions is a collection of SSH host certificate options.
  137. // It's an alias of SSHUserCertificateOptions, as the options are the same
  138. // for both types of certificates.
  139. type SSHHostCertificateOptions SSHUserCertificateOptions
  140. // SSHNameOptions models the SSH name policy configuration.
  141. type SSHNameOptions struct {
  142. DNSDomains []string `json:"dns,omitempty"`
  143. IPRanges []string `json:"ip,omitempty"`
  144. EmailAddresses []string `json:"email,omitempty"`
  145. Principals []string `json:"principal,omitempty"`
  146. }
  147. // GetAllowedNameOptions returns the AllowedSSHNameOptions, which models the
  148. // names that a provisioner is authorized to sign SSH certificates for.
  149. func (o *SSHUserCertificateOptions) GetAllowedNameOptions() *SSHNameOptions {
  150. if o == nil {
  151. return nil
  152. }
  153. return o.AllowedNames
  154. }
  155. // GetDeniedNameOptions returns the DeniedSSHNameOptions, which models the
  156. // names that a provisioner is NOT authorized to sign SSH certificates for.
  157. func (o *SSHUserCertificateOptions) GetDeniedNameOptions() *SSHNameOptions {
  158. if o == nil {
  159. return nil
  160. }
  161. return o.DeniedNames
  162. }
  163. // HasNames checks if the SSHNameOptions has one or more
  164. // names configured.
  165. func (o *SSHNameOptions) HasNames() bool {
  166. return len(o.DNSDomains) > 0 ||
  167. len(o.IPRanges) > 0 ||
  168. len(o.EmailAddresses) > 0 ||
  169. len(o.Principals) > 0
  170. }