constants.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package sts
  2. // Store Types
  3. const (
  4. StoreTypeMemory = "memory"
  5. StoreTypeFiler = "filer"
  6. StoreTypeRedis = "redis"
  7. )
  8. // Provider Types
  9. const (
  10. ProviderTypeOIDC = "oidc"
  11. ProviderTypeLDAP = "ldap"
  12. ProviderTypeSAML = "saml"
  13. )
  14. // Policy Effects
  15. const (
  16. EffectAllow = "Allow"
  17. EffectDeny = "Deny"
  18. )
  19. // Default Paths - aligned with filer /etc/ convention
  20. const (
  21. DefaultSessionBasePath = "/etc/iam/sessions"
  22. DefaultPolicyBasePath = "/etc/iam/policies"
  23. DefaultRoleBasePath = "/etc/iam/roles"
  24. )
  25. // Default Values
  26. const (
  27. DefaultTokenDuration = 3600 // 1 hour in seconds
  28. DefaultMaxSessionLength = 43200 // 12 hours in seconds
  29. DefaultIssuer = "seaweedfs-sts"
  30. DefaultStoreType = StoreTypeFiler // Default store type for persistence
  31. MinSigningKeyLength = 16 // Minimum signing key length in bytes
  32. )
  33. // Configuration Field Names
  34. const (
  35. ConfigFieldFilerAddress = "filerAddress"
  36. ConfigFieldBasePath = "basePath"
  37. ConfigFieldIssuer = "issuer"
  38. ConfigFieldClientID = "clientId"
  39. ConfigFieldClientSecret = "clientSecret"
  40. ConfigFieldJWKSUri = "jwksUri"
  41. ConfigFieldScopes = "scopes"
  42. ConfigFieldUserInfoUri = "userInfoUri"
  43. ConfigFieldRedirectUri = "redirectUri"
  44. )
  45. // Error Messages
  46. const (
  47. ErrConfigCannotBeNil = "config cannot be nil"
  48. ErrProviderCannotBeNil = "provider cannot be nil"
  49. ErrProviderNameEmpty = "provider name cannot be empty"
  50. ErrProviderTypeEmpty = "provider type cannot be empty"
  51. ErrTokenCannotBeEmpty = "token cannot be empty"
  52. ErrSessionTokenCannotBeEmpty = "session token cannot be empty"
  53. ErrSessionIDCannotBeEmpty = "session ID cannot be empty"
  54. ErrSTSServiceNotInitialized = "STS service not initialized"
  55. ErrProviderNotInitialized = "provider not initialized"
  56. ErrInvalidTokenDuration = "token duration must be positive"
  57. ErrInvalidMaxSessionLength = "max session length must be positive"
  58. ErrIssuerRequired = "issuer is required"
  59. ErrSigningKeyTooShort = "signing key must be at least %d bytes"
  60. ErrFilerAddressRequired = "filer address is required"
  61. ErrClientIDRequired = "clientId is required for OIDC provider"
  62. ErrUnsupportedStoreType = "unsupported store type: %s"
  63. ErrUnsupportedProviderType = "unsupported provider type: %s"
  64. ErrInvalidTokenFormat = "invalid session token format: %w"
  65. ErrSessionValidationFailed = "session validation failed: %w"
  66. ErrInvalidToken = "invalid token: %w"
  67. ErrTokenNotValid = "token is not valid"
  68. ErrInvalidTokenClaims = "invalid token claims"
  69. ErrInvalidIssuer = "invalid issuer"
  70. ErrMissingSessionID = "missing session ID"
  71. )
  72. // JWT Claims
  73. const (
  74. JWTClaimIssuer = "iss"
  75. JWTClaimSubject = "sub"
  76. JWTClaimAudience = "aud"
  77. JWTClaimExpiration = "exp"
  78. JWTClaimIssuedAt = "iat"
  79. JWTClaimTokenType = "token_type"
  80. )
  81. // Token Types
  82. const (
  83. TokenTypeSession = "session"
  84. TokenTypeAccess = "access"
  85. TokenTypeRefresh = "refresh"
  86. )
  87. // AWS STS Actions
  88. const (
  89. ActionAssumeRole = "sts:AssumeRole"
  90. ActionAssumeRoleWithWebIdentity = "sts:AssumeRoleWithWebIdentity"
  91. ActionAssumeRoleWithCredentials = "sts:AssumeRoleWithCredentials"
  92. ActionValidateSession = "sts:ValidateSession"
  93. )
  94. // Session File Prefixes
  95. const (
  96. SessionFilePrefix = "session_"
  97. SessionFileExt = ".json"
  98. PolicyFilePrefix = "policy_"
  99. PolicyFileExt = ".json"
  100. RoleFileExt = ".json"
  101. )
  102. // HTTP Headers
  103. const (
  104. HeaderAuthorization = "Authorization"
  105. HeaderContentType = "Content-Type"
  106. HeaderUserAgent = "User-Agent"
  107. )
  108. // Content Types
  109. const (
  110. ContentTypeJSON = "application/json"
  111. ContentTypeFormURLEncoded = "application/x-www-form-urlencoded"
  112. )
  113. // Default Test Values
  114. const (
  115. TestSigningKey32Chars = "test-signing-key-32-characters-long"
  116. TestIssuer = "test-sts"
  117. TestClientID = "test-client"
  118. TestSessionID = "test-session-123"
  119. TestValidToken = "valid_test_token"
  120. TestInvalidToken = "invalid_token"
  121. TestExpiredToken = "expired_token"
  122. )