oidc.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package integrations
  2. import "gorm.io/gorm"
  3. // OIDCIntegrationClient is the name of an OIDC auth mechanism client
  4. type OIDCIntegrationClient string
  5. // The supported OIDC auth mechanism clients
  6. const (
  7. OIDCKube OIDCIntegrationClient = "kube"
  8. )
  9. // OIDCIntegration is an auth mechanism that uses oidc. Spec:
  10. // https://openid.net/specs/openid-connect-core-1_0.html
  11. type OIDCIntegration struct {
  12. gorm.Model
  13. // The name of the auth mechanism
  14. Client OIDCIntegrationClient `json:"client"`
  15. // The id of the user that linked this auth mechanism
  16. UserID uint `json:"user_id"`
  17. // The project that this integration belongs to
  18. ProjectID uint `json:"project_id"`
  19. // ------------------------------------------------------------------
  20. // All fields encrypted before storage.
  21. // ------------------------------------------------------------------
  22. // The "Issuer Identifier" of the OIDC spec (16.15)
  23. IssuerURL []byte `json:"idp-issuer-url"`
  24. // The ID issued to the Relying Party
  25. ClientID []byte `json:"client-id"`
  26. // The secret issued to the Relying Party
  27. //
  28. // This is present because it used to be a required field in a kubeconfig.
  29. // However, because the kube apiserver acts as a Relying Party, the client
  30. // secret is not necessary.
  31. ClientSecret []byte `json:"client-secret"`
  32. // The CA data -- certificate check must be performed (16.17)
  33. CertificateAuthorityData []byte `json:"idp-certificate-authority-data"`
  34. // The user's JWT id token
  35. IDToken []byte `json:"id-token"`
  36. // The user's refresh token
  37. RefreshToken []byte `json:"refresh-token"`
  38. }
  39. // OIDCIntegrationExternal is a OIDCIntegration to be shared over REST
  40. type OIDCIntegrationExternal struct {
  41. ID uint `json:"id"`
  42. // The name of the auth mechanism
  43. Client OIDCIntegrationClient `json:"client"`
  44. // The id of the user that linked this auth mechanism
  45. UserID uint `json:"user_id"`
  46. // The project that this integration belongs to
  47. ProjectID uint `json:"project_id"`
  48. }
  49. // Externalize generates an external KubeIntegration to be shared over REST
  50. func (o *OIDCIntegration) Externalize() *OIDCIntegrationExternal {
  51. return &OIDCIntegrationExternal{
  52. ID: o.ID,
  53. Client: o.Client,
  54. UserID: o.UserID,
  55. ProjectID: o.ProjectID,
  56. }
  57. }
  58. // ToProjectIntegration converts a gcp integration to a project integration
  59. func (o *OIDCIntegration) ToProjectIntegration(
  60. category string,
  61. service IntegrationService,
  62. ) *ProjectIntegration {
  63. return &ProjectIntegration{
  64. ID: o.ID,
  65. ProjectID: o.ProjectID,
  66. AuthMechanism: "oidc",
  67. Category: category,
  68. Service: service,
  69. }
  70. }