Subtype Id registration moved to its own package (#1416)

* Allow repo packages to register subtypes and id prefixes. 
* Refactor out request authentication logic to a new package as a sibling to handler.
This commit is contained in:
Todd Knight authored and GitHub committed 2021-07-27 09:59:52 -07:00
1 parent ab6f3eaeb4
commit 10e8aeae4b
62 files changed
+603 -597

No files matched your search

+648
View File
@@ -0,0 +1,648 @@
package auth
import (
"context"
"fmt"
"net/http"
"strings"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
"github.com/hashicorp/boundary/internal/gen/controller/tokens"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/sdk/recovery"
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/kr/pretty"
"github.com/mr-tron/base58"
"google.golang.org/protobuf/proto"
)
type TokenFormat int
const (
// We weren't given one or couldn't parse it
AuthTokenTypeUnknown TokenFormat = iota
// Came in via the Authentication: Bearer header
AuthTokenTypeBearer
// Came in via split cookies
AuthTokenTypeSplitCookie
// It's of recovery type
AuthTokenTypeRecoveryKms
)
const (
AnonymousUserId = "u_anon"
)
type key int
var verifierKey key
// RequestInfo contains request parameters necessary for checking authn/authz
type RequestInfo struct {
Path string
Method string
PublicId string
EncryptedToken string
Token string
TokenFormat TokenFormat
// The following are useful for tests
scopeIdOverride string
userIdOverride string
DisableAuthzFailures bool
DisableAuthEntirely bool
}
type VerifyResults struct {
UserId string
AuthTokenId string
Error error
Scope *scopes.ScopeInfo
// AuthenticatedFinished means that the request has passed through the
// authentication system successfully. This does _not_ indicate whether a
// token was provided on the request. Requests for `u_anon` will still have
// this set true! This is because if a request has a token that is invalid,
// we fall back to `u_anon` because the request may still be allowed for any
// anonymous user; it simply fails to validate for and look up grants for an
// actual known user.
//
// A good example is when running dev mode twice. The first time you can
// authenticate and get a token which is saved by the token helper. The
// second time, you run a command and it reads the token from the helper.
// That token is no longer valid, but if the action is granted to `u_anon`
// the action should still succeed. What happens internally is that the
// token fails to look up a non-anonymous user, so we fallback to the
// anonymous user, which is the default.
//
// If you want to know if the request had a valid token provided, use a
// switch on UserId. Anything that isn't `u_anon` will have to have had a
// valid token provided. And a valid token will never fall back to `u_anon`.
AuthenticationFinished bool
// RoundTripValue can be set to allow the function performing authentication
// (often accompanied by lookup(s)) to return a result of that lookup to the
// calling function. It is opaque to this package.
RoundTripValue interface{}
// Used for additional verification
v *verifier
}
type verifier struct {
logger hclog.Logger
iamRepoFn common.IamRepoFactory
authTokenRepoFn common.AuthTokenRepoFactory
serversRepoFn common.ServersRepoFactory
kms *kms.Kms
requestInfo RequestInfo
res *perms.Resource
act action.Type
ctx context.Context
acl perms.ACL
}
// NewVerifierContext creates a context that carries a verifier object from the
// HTTP handlers to the gRPC service handlers. It should only be created in the
// HTTP handler and should exist for every request that reaches the service
// handlers.
func NewVerifierContext(ctx context.Context,
logger hclog.Logger,
iamRepoFn common.IamRepoFactory,
authTokenRepoFn common.AuthTokenRepoFactory,
serversRepoFn common.ServersRepoFactory,
kms *kms.Kms,
requestInfo RequestInfo) context.Context {
return context.WithValue(ctx, verifierKey, &verifier{
logger: logger,
iamRepoFn: iamRepoFn,
authTokenRepoFn: authTokenRepoFn,
serversRepoFn: serversRepoFn,
kms: kms,
requestInfo: requestInfo,
})
}
// Verify takes in a context that has expected parameters as values and runs an
// authn/authz check. It returns a user ID, the scope ID for the request (which
// may come from the URL and may come from the token) and whether or not to
// proceed, e.g. whether the authn/authz check resulted in failure. If an error
// occurs it's logged to the system log.
func Verify(ctx context.Context, opt ...Option) (ret VerifyResults) {
ret.Error = handlers.ForbiddenError()
v, ok := ctx.Value(verifierKey).(*verifier)
if !ok {
// We don't have a logger yet and this should never happen in any
// context we won't catch in tests
panic("no verifier information found in context")
}
ret.v = v
v.ctx = ctx
opts := getOpts(opt...)
ret.Scope = new(scopes.ScopeInfo)
// Note: we don't call RequestContextFromCtx here because that performs a
// SelfOrDefault. That's useful in the handlers, but here we don't want to
// do anything if it's nil. That's mainly useful in tests where
// DisableAuthEntirely is set. Later, if we don't have the value set at all,
// we have some safeguards to ensure we fail safe (e.g. no output fields at
// all). So it provides a good indication as well whether we have set this
// where and when needed.
var reqInfo *requests.RequestContext
reqInfoRaw := ctx.Value(requests.ContextRequestInformationKey)
if reqInfoRaw != nil {
reqInfo = reqInfoRaw.(*requests.RequestContext)
}
// In tests we often simply disable auth so we can test the service handlers
// without fuss
if v.requestInfo.DisableAuthEntirely {
const op = "auth.(disabled).lookupScope"
ret.Scope.Id = v.requestInfo.scopeIdOverride
if ret.Scope.Id == "" {
ret.Scope.Id = opts.withScopeId
}
// Look up scope details to return. We can skip a lookup when using the
// global scope
switch ret.Scope.Id {
case "global":
ret.Scope = &scopes.ScopeInfo{
Id: scope.Global.String(),
Type: scope.Global.String(),
Name: scope.Global.String(),
Description: "Global Scope",
ParentScopeId: "",
}
default:
iamRepo, err := v.iamRepoFn()
if err != nil {
ret.Error = errors.Wrap(err, op, errors.WithMsg("failed to get iam repo"))
return
}
scp, err := iamRepo.LookupScope(v.ctx, ret.Scope.Id)
if err != nil {
ret.Error = errors.Wrap(err, op)
return
}
if scp == nil {
ret.Error = errors.New(errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", ret.Scope.Id))
return
}
ret.Scope = &scopes.ScopeInfo{
Id: scp.GetPublicId(),
Type: scp.GetType(),
Name: scp.GetName(),
Description: scp.GetDescription(),
ParentScopeId: scp.GetParentId(),
}
}
ret.UserId = v.requestInfo.userIdOverride
if reqInfo != nil {
reqInfo.UserId = ret.UserId
}
ret.Error = nil
return
}
v.act = opts.withAction
v.res = &perms.Resource{
ScopeId: opts.withScopeId,
Id: opts.withId,
Pin: opts.withPin,
Type: opts.withType,
}
// Global scope has no parent ID; account for this
if opts.withId == scope.Global.String() && opts.withType == resource.Scope {
v.res.ScopeId = scope.Global.String()
}
if v.requestInfo.EncryptedToken != "" {
v.decryptToken()
}
var authResults perms.ACLResults
var err error
authResults, ret.UserId, ret.Scope, v.acl, err = v.performAuthCheck()
if err != nil {
v.logger.Error("error performing authn/authz check", "error", err)
return
}
ret.AuthTokenId = v.requestInfo.PublicId
ret.AuthenticationFinished = authResults.AuthenticationFinished
if !authResults.Authorized {
if v.requestInfo.DisableAuthzFailures {
ret.Error = nil
// TODO: Decide whether to remove this
v.logger.Info("failed authz info for request", "resource", pretty.Sprint(v.res), "user_id", ret.UserId, "action", v.act.String())
} else {
// If the anon user was used (either no token, or invalid (perhaps
// expired) token), return a 401. That way if it's an authn'd user
// that is not authz'd we'll return 403 to be explicit.
if ret.UserId == AnonymousUserId {
ret.Error = handlers.UnauthenticatedError()
}
return
}
}
if reqInfo != nil {
reqInfo.UserId = ret.UserId
reqInfo.OutputFields = authResults.OutputFields
}
ret.Error = nil
return
}
func (v *verifier) decryptToken() {
switch v.requestInfo.TokenFormat {
case AuthTokenTypeUnknown:
// Nothing to decrypt
return
case AuthTokenTypeBearer, AuthTokenTypeSplitCookie:
if v.kms == nil {
v.logger.Trace("decrypt token: no KMS object available to authz system")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
tokenRepo, err := v.authTokenRepoFn()
if err != nil {
v.logger.Warn("decrypt bearer token: failed to get authtoken repo", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
at, err := tokenRepo.LookupAuthToken(v.ctx, v.requestInfo.PublicId)
if err != nil {
v.logger.Trace("decrypt bearer token: failed to look up auth token by public ID", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
if at == nil {
v.logger.Trace("decrypt bearer token: nil result from looking up auth token by public ID")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
tokenWrapper, err := v.kms.GetWrapper(v.ctx, at.GetScopeId(), kms.KeyPurposeTokens)
if err != nil {
v.logger.Warn("decrypt bearer token: unable to get wrapper for tokens; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
version := v.requestInfo.EncryptedToken[0:len(globals.ServiceTokenV1)]
switch version {
case globals.ServiceTokenV1:
default:
v.logger.Trace("decrypt bearer token: unknown token encryption version; continuing as anonymous user", "version", version)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
marshaledToken, err := base58.FastBase58Decoding(v.requestInfo.EncryptedToken[len(globals.ServiceTokenV1):])
if err != nil {
v.logger.Trace("decrypt bearer token: error unmarshaling base58 token; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
blobInfo := new(wrapping.EncryptedBlobInfo)
if err := proto.Unmarshal(marshaledToken, blobInfo); err != nil {
v.logger.Trace("decrypt bearer token: error decoding encrypted token; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
s1Bytes, err := tokenWrapper.Decrypt(v.ctx, blobInfo, []byte(v.requestInfo.PublicId))
if err != nil {
v.logger.Trace("decrypt bearer token: error decrypting encrypted token; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
var s1Info tokens.S1TokenInfo
if err := proto.Unmarshal(s1Bytes, &s1Info); err != nil {
v.logger.Trace("decrypt bearer token: error unmarshaling token info; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
if v.requestInfo.TokenFormat == AuthTokenTypeUnknown || s1Info.Token == "" || v.requestInfo.PublicId == "" {
v.logger.Trace("decrypt bearer token: after parsing, could not find valid token; continuing as anonymous user")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
v.requestInfo.Token = s1Info.Token
return
case AuthTokenTypeRecoveryKms:
if v.kms == nil {
v.logger.Trace("decrypt recovery token: no KMS object available to authz system")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
wrapper := v.kms.GetExternalWrappers().Recovery()
if wrapper == nil {
v.logger.Trace("decrypt recovery token: no recovery KMS is available")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
info, err := recovery.ParseRecoveryToken(v.ctx, wrapper, v.requestInfo.EncryptedToken)
if err != nil {
v.logger.Trace("decrypt recovery token: error parsing and validating recovery token", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
// If we add the validity period to the creation time (which we've
// verified is before the current time, with a minute of fudging), and
// it's before now, it's expired and might be a replay.
if info.CreationTime.Add(globals.RecoveryTokenValidityPeriod).Before(time.Now()) {
v.logger.Warn("decrypt recovery token: recovery token has expired (possible replay attack)")
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
repo, err := v.serversRepoFn()
if err != nil {
v.logger.Trace("decrypt recovery token: error fetching servers repo", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
if err := repo.AddRecoveryNonce(v.ctx, info.Nonce); err != nil {
v.logger.Warn("decrypt recovery token: error adding nonce to database (possible replay attack)", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
v.logger.Warn("recovery KMS was used to authorize a call", "url", v.requestInfo.Path, "method", v.requestInfo.Method)
}
}
func (v verifier) performAuthCheck() (aclResults perms.ACLResults, userId string, scopeInfo *scopes.ScopeInfo, retAcl perms.ACL, retErr error) {
const op = "auth.(verifier).performAuthCheck"
// Ensure we return an error by default if we forget to set this somewhere
retErr = errors.New(errors.Unknown, op, "default auth error")
// Make the linter happy
_ = retErr
scopeInfo = new(scopes.ScopeInfo)
userId = AnonymousUserId
var accountId string
// Validate the token and fetch the corresponding user ID
switch v.requestInfo.TokenFormat {
case AuthTokenTypeUnknown:
// Nothing; remain as the anonymous user
case AuthTokenTypeRecoveryKms:
// We validated the encrypted token in decryptToken and handled the
// nonces there, so just set the user
userId = "u_recovery"
case AuthTokenTypeBearer, AuthTokenTypeSplitCookie:
if v.requestInfo.Token == "" {
// This will end up staying as the anonymous user
break
}
tokenRepo, err := v.authTokenRepoFn()
if err != nil {
retErr = errors.Wrap(err, op)
return
}
at, err := tokenRepo.ValidateToken(v.ctx, v.requestInfo.PublicId, v.requestInfo.Token)
if err != nil {
// Continue as the anonymous user as maybe this token is expired but
// we can still perform the action
v.logger.Error("perform auth check: error validating token; continuing as anonymous user", "error", err)
break
}
if at != nil {
accountId = at.GetAuthAccountId()
userId = at.GetIamUserId()
if userId == "" {
v.logger.Warn("perform auth check: valid token did not map to a user, likely because no account is associated with the user any longer; continuing as u_anon", "token_id", at.GetPublicId())
userId = AnonymousUserId
accountId = ""
}
}
}
iamRepo, err := v.iamRepoFn()
if err != nil {
retErr = errors.Wrap(err, op, errors.WithMsg("failed to get iam repo"))
return
}
// Look up scope details to return. We can skip a lookup when using the
// global scope
switch v.res.ScopeId {
case "global":
scopeInfo = &scopes.ScopeInfo{
Id: scope.Global.String(),
Type: scope.Global.String(),
Name: scope.Global.String(),
Description: "Global Scope",
ParentScopeId: "",
}
default:
scp, err := iamRepo.LookupScope(v.ctx, v.res.ScopeId)
if err != nil {
retErr = errors.Wrap(err, op)
return
}
if scp == nil {
retErr = errors.New(errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", v.res.ScopeId))
return
}
scopeInfo = &scopes.ScopeInfo{
Id: scp.GetPublicId(),
Type: scp.GetType(),
Name: scp.GetName(),
Description: scp.GetDescription(),
ParentScopeId: scp.GetParentId(),
}
}
// At this point we don't need to look up grants since it's automatically allowed
if v.requestInfo.TokenFormat == AuthTokenTypeRecoveryKms {
aclResults.AuthenticationFinished = true
aclResults.Authorized = true
retErr = nil
return
}
var parsedGrants []perms.Grant
var grantTuples []perms.GrantTuple
// Fetch and parse grants for this user ID (which may include grants for
// u_anon and u_auth)
grantTuples, err = iamRepo.GrantsForUser(v.ctx, userId)
if err != nil {
retErr = errors.Wrap(err, op)
return
}
parsedGrants = make([]perms.Grant, 0, len(grantTuples))
// Note: Below, we always skip validation so that we don't error on formats
// that we've since restricted, e.g. "id=foo;actions=create,read". These
// will simply not have an effect.
for _, pair := range grantTuples {
parsed, err := perms.Parse(
pair.ScopeId,
pair.Grant,
perms.WithUserId(userId),
perms.WithAccountId(accountId),
perms.WithSkipFinalValidation(true))
if err != nil {
retErr = errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("failed to parse grant %#v", pair.Grant)))
return
}
parsedGrants = append(parsedGrants, parsed)
}
retAcl = perms.NewACL(parsedGrants...)
aclResults = retAcl.Allowed(*v.res, v.act)
// We don't set authenticated above because setting this but not authorized
// is used for further permissions checks, such as during recursive listing.
// So we want to make sure any code relying on that has the full set of
// grants successfully loaded.
aclResults.AuthenticationFinished = true
retErr = nil
return
}
// FetchActionSetForId returns the allowed actions for a given ID using the
// current set of ACLs and all other parameters the same (user, etc.)
func (r *VerifyResults) FetchActionSetForId(ctx context.Context, id string, availableActions action.ActionSet, opt ...Option) action.ActionSet {
return r.fetchActions(id, resource.Unknown, availableActions, opt...)
}
// FetchActionSetForType returns the allowed actions for a given collection type
// using the current set of ACLs and all other parameters the same (user, etc.)
func (r *VerifyResults) FetchActionSetForType(ctx context.Context, typ resource.Type, availableActions action.ActionSet, opt ...Option) action.ActionSet {
return r.fetchActions("", typ, availableActions, opt...)
}
func (r *VerifyResults) fetchActions(id string, typ resource.Type, availableActions action.ActionSet, opt ...Option) action.ActionSet {
switch {
case r.v.requestInfo.DisableAuthEntirely,
r.v.requestInfo.TokenFormat == AuthTokenTypeRecoveryKms:
// TODO: See if we can be better about what we return with the anonymous
// user and recovery KMS, perhaps given exclusionary options for each
return availableActions
}
opts := getOpts(opt...)
res := opts.withResource
// If not passed in, use what's already been populated through verification
if res == nil {
res = r.v.res
}
// If this is being called directly we may not have a resource yet
if res == nil {
res = new(perms.Resource)
}
if id != "" {
res.Id = id
}
if typ != resource.Unknown {
res.Type = typ
}
ret := make(action.ActionSet, 0, len(availableActions))
for _, act := range availableActions {
if r.v.acl.Allowed(*res, act).Authorized {
ret = append(ret, act)
}
}
if len(ret) == 0 {
return nil
}
return ret
}
func (r *VerifyResults) FetchOutputFields(res perms.Resource, act action.Type) perms.OutputFieldsMap {
switch {
case r.v.requestInfo.TokenFormat == AuthTokenTypeRecoveryKms:
return perms.OutputFieldsMap{"*": true}
case r.v.requestInfo.DisableAuthEntirely:
return nil
}
return r.v.acl.Allowed(res, act).OutputFields
}
// GetTokenFromRequest pulls the token from either the Authorization header or
// split cookies and parses it. If it cannot be parsed successfully, the issue
// is logged and we return blank, so logic will continue as the anonymous user.
// The public ID and _encrypted_ token are returned along with the token format.
func GetTokenFromRequest(logger hclog.Logger, kmsCache *kms.Kms, req *http.Request) (string, string, TokenFormat) {
// First, get the token, either from the authorization header or from split
// cookies
var receivedTokenType TokenFormat
var fullToken string
if authHeader := req.Header.Get("Authorization"); authHeader != "" {
headerSplit := strings.SplitN(strings.TrimSpace(authHeader), " ", 2)
if len(headerSplit) == 2 && strings.EqualFold(strings.TrimSpace(headerSplit[0]), "bearer") {
receivedTokenType = AuthTokenTypeBearer
fullToken = strings.TrimSpace(headerSplit[1])
}
}
if receivedTokenType != AuthTokenTypeBearer {
var httpCookiePayload string
var jsCookiePayload string
if hc, err := req.Cookie(handlers.HttpOnlyCookieName); err == nil {
httpCookiePayload = hc.Value
}
if jc, err := req.Cookie(handlers.JsVisibleCookieName); err == nil {
jsCookiePayload = jc.Value
}
if httpCookiePayload != "" && jsCookiePayload != "" {
receivedTokenType = AuthTokenTypeSplitCookie
fullToken = jsCookiePayload + httpCookiePayload
}
}
if receivedTokenType == AuthTokenTypeUnknown || fullToken == "" {
// We didn't find auth info or a client screwed up and put in a blank
// header instead of nothing at all, so return blank which will indicate
// the anonymouse user
return "", "", AuthTokenTypeUnknown
}
if strings.HasPrefix(fullToken, "r_") {
return "", fullToken, AuthTokenTypeRecoveryKms
}
splitFullToken := strings.Split(fullToken, "_")
if len(splitFullToken) != 3 {
logger.Trace("get token from request: unexpected number of segments in token; continuing as anonymous user", "expected", 3, "found", len(splitFullToken))
return "", "", AuthTokenTypeUnknown
}
publicId := strings.Join(splitFullToken[0:2], "_")
encryptedToken := splitFullToken[2]
return publicId, encryptedToken, receivedTokenType
}
@@ -0,0 +1,135 @@
package auth
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuthTokenAuthenticator(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
rw := db.New(conn)
logger := hclog.New(nil)
wrapper := db.TestWrapper(t)
kms := kms.TestKms(t, conn, wrapper)
tokenRepo, err := authtoken.NewRepository(rw, rw, kms)
require.NoError(t, err)
iamRepo := iam.TestRepo(t, conn, wrapper)
tokenRepoFn := func() (*authtoken.Repository, error) {
return tokenRepo, nil
}
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
}
o, _ := iam.TestScopes(t, iamRepo)
at := authtoken.TestAuthToken(t, conn, kms, o.GetPublicId())
encToken, err := authtoken.EncryptToken(context.Background(), kms, o.GetPublicId(), at.GetPublicId(), at.GetToken())
require.NoError(t, err)
tokValue := at.GetPublicId() + "_" + encToken
jsCookieVal, httpCookieVal := tokValue[:len(tokValue)/2], tokValue[len(tokValue)/2:]
cases := []struct {
name string
headers map[string]string
cookies []http.Cookie
userId string
tokenFormat TokenFormat
}{
{
name: "Empty headers",
headers: map[string]string{},
tokenFormat: AuthTokenTypeUnknown,
},
{
name: "Bearer token",
headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", tokValue)},
userId: at.GetIamUserId(),
tokenFormat: AuthTokenTypeBearer,
},
{
name: "Split cookie token",
cookies: []http.Cookie{
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
},
userId: at.GetIamUserId(),
tokenFormat: AuthTokenTypeSplitCookie,
},
{
name: "Split cookie token only http cookie",
cookies: []http.Cookie{
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
},
tokenFormat: AuthTokenTypeUnknown,
},
{
name: "Split cookie token only js cookie",
cookies: []http.Cookie{
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
},
tokenFormat: AuthTokenTypeUnknown,
},
{
name: "Cookie and auth header",
headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", tokValue)},
cookies: []http.Cookie{
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
},
userId: at.GetIamUserId(),
tokenFormat: AuthTokenTypeBearer,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
req := httptest.NewRequest("GET", "http://127.0.0.1/v1/scopes/o_1", nil)
for k, v := range tc.headers {
req.Header.Set(k, v)
}
for _, c := range tc.cookies {
req.AddCookie(&c)
}
// Add values for authn/authz checking
requestInfo := RequestInfo{
Path: req.URL.Path,
Method: req.Method,
}
requestInfo.PublicId, requestInfo.EncryptedToken, requestInfo.TokenFormat = GetTokenFromRequest(logger, kms, req)
assert.Equal(t, tc.tokenFormat, requestInfo.TokenFormat)
if tc.userId == "" {
return
}
ctx := NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
v, ok := ctx.Value(verifierKey).(*verifier)
require.True(t, ok)
require.NotNil(t, v)
v.decryptToken()
at, err := tokenRepo.ValidateToken(ctx, v.requestInfo.PublicId, v.requestInfo.Token)
require.NoError(t, err)
assert.Equal(t, tc.userId, at.GetIamUserId())
})
}
}
@@ -0,0 +1,45 @@
package auth
import (
"context"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/go-secure-stdlib/strutil"
"google.golang.org/protobuf/types/known/structpb"
)
// CalculateAuthorizedCollectionActions returns authorized actions for the given
// inputs.
//
// NOTE: Eventually we should unit test this, but for now every service handler
// is validating the results of this (as it was pulled out of the service
// handlers).
func CalculateAuthorizedCollectionActions(ctx context.Context,
authResults VerifyResults,
mapToRange map[resource.Type]action.ActionSet,
scopeId, pin string) (map[string]*structpb.ListValue, error) {
res := &perms.Resource{
ScopeId: scopeId,
Pin: pin,
}
// Range over the defined collections and check permissions against those
// collections.
var ret map[string]*structpb.ListValue
for k, v := range mapToRange {
res.Type = k
acts := authResults.FetchActionSetForType(ctx, k, v, WithResource(res)).Strings()
if len(acts) > 0 {
if ret == nil {
ret = make(map[string]*structpb.ListValue)
}
lv, err := structpb.NewList(strutil.StringListToInterfaceList(acts))
if err != nil {
return nil, err
}
ret[k.String()+"s"] = lv
}
}
return ret, nil
}
@@ -0,0 +1,98 @@
package auth
import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
)
func getOpts(opt ...Option) options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// Option - how Options are passed as arguments
type Option func(*options)
// options = how options are represented
type options struct {
withScopeId string
withPin string
withId string
withAction action.Type
withType resource.Type
withUserId string
withKms *kms.Kms
withRecoveryTokenNotAllowed bool
withAnonymousUserNotAllowed bool
withResource *perms.Resource
}
func getDefaultOptions() options {
return options{}
}
func WithScopeId(id string) Option {
return func(o *options) {
o.withScopeId = id
}
}
func WithPin(pin string) Option {
return func(o *options) {
o.withPin = pin
}
}
func WithId(id string) Option {
return func(o *options) {
o.withId = id
}
}
func WithAction(action action.Type) Option {
return func(o *options) {
o.withAction = action
}
}
func WithType(rt resource.Type) Option {
return func(o *options) {
o.withType = rt
}
}
func WithUserId(id string) Option {
return func(o *options) {
o.withUserId = id
}
}
func WithKms(kms *kms.Kms) Option {
return func(o *options) {
o.withKms = kms
}
}
func WithRecoveryTokenNotAllowed(notAllowed bool) Option {
return func(o *options) {
o.withRecoveryTokenNotAllowed = notAllowed
}
}
func WithAnonymousUserNotAllowed(notAllowed bool) Option {
return func(o *options) {
o.withAnonymousUserNotAllowed = notAllowed
}
}
// WithResource specifies a resouce to use
func WithResource(resource *perms.Resource) Option {
return func(o *options) {
o.withResource = resource
}
}
@@ -0,0 +1,45 @@
package auth
import (
"testing"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/stretchr/testify/assert"
)
// Test_GetOpts provides unit tests for GetOpts and all the options
func Test_GetOpts(t *testing.T) {
t.Parallel()
withKms := new(kms.Kms)
res := new(perms.Resource)
opts := getOpts(
WithScopeId("foo"),
WithPin("bar"),
WithId("zip"),
WithAction(action.AddHosts),
WithType(resource.Group),
WithUserId("user"),
WithKms(withKms),
WithRecoveryTokenNotAllowed(true),
WithAnonymousUserNotAllowed(true),
WithResource(res),
)
exp := options{
withScopeId: "foo",
withPin: "bar",
withId: "zip",
withAction: action.AddHosts,
withType: resource.Group,
withUserId: "user",
withKms: withKms,
withRecoveryTokenNotAllowed: true,
withAnonymousUserNotAllowed: true,
withResource: res,
}
assert.Equal(t, exp, opts)
}
@@ -0,0 +1,26 @@
package auth
import (
"context"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/common"
)
// DisabledAuthTestContext is meant for testing, and uses a context that has
// auth checking entirely disabled. Supported options: WithScopeId an WithUserId
// are used directly; WithKms is passed through into the verifier context.
func DisabledAuthTestContext(iamRepoFn common.IamRepoFactory, scopeId string, opt ...Option) context.Context {
reqInfo := RequestInfo{DisableAuthEntirely: true}
opts := getOpts(opt...)
reqInfo.scopeIdOverride = opts.withScopeId
if reqInfo.scopeIdOverride == "" {
reqInfo.scopeIdOverride = scopeId
}
reqInfo.userIdOverride = opts.withUserId
if reqInfo.userIdOverride == "" {
reqInfo.userIdOverride = "u_auth"
}
requestContext := context.WithValue(context.Background(), requests.ContextRequestInformationKey, &requests.RequestContext{})
return NewVerifierContext(requestContext, nil, iamRepoFn, nil, nil, opts.withKms, reqInfo)
}
@@ -3,11 +3,11 @@ package scopeids
import (
"context"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
@@ -4,13 +4,13 @@ import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/db"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/groups"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/sessions"
+1 -1
View File
@@ -14,11 +14,11 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/common"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/accounts"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authmethods"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/credentiallibraries"
@@ -19,10 +19,12 @@ import (
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
requestauth "github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/subtypes"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
@@ -55,8 +57,8 @@ var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = map[auth.Subtype]action.ActionSet{
auth.PasswordSubtype: {
IdActions = map[subtypes.Subtype]action.ActionSet{
password.Subtype: {
action.NoOp,
action.Read,
action.Update,
@@ -64,7 +66,7 @@ var (
action.SetPassword,
action.ChangePassword,
},
auth.OidcSubtype: {
oidc.Subtype: {
action.NoOp,
action.Read,
action.Update,
@@ -142,7 +144,7 @@ func (s Service) ListAccounts(ctx context.Context, req *pbs.ListAccountsRequest)
}
for _, acct := range ul {
res.Id = acct.GetPublicId()
authorizedActions := authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())], auth.WithResource(&res)).Strings()
authorizedActions := authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())], requestauth.WithResource(&res)).Strings()
if len(authorizedActions) == 0 {
continue
}
@@ -391,7 +393,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
var acct auth.Account
var mgIds []string
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
repo, err := s.pwRepoFn()
if err != nil {
return nil, nil, err
@@ -404,7 +406,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
return nil, nil, err
}
acct = a
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, nil, err
@@ -520,7 +522,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
}
var out auth.Account
switch auth.SubtypeFromId(am.GetPublicId()) {
case auth.PasswordSubtype:
case password.Subtype:
am, err := s.createPwInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(err, op)
@@ -529,7 +531,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
}
out = am
case auth.OidcSubtype:
case oidc.Subtype:
am, err := s.createOidcInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(err, op)
@@ -613,7 +615,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
const op = "accounts.(Service).updateInRepo"
var out auth.Account
switch auth.SubtypeFromId(req.GetId()) {
case auth.PasswordSubtype:
case password.Subtype:
a, err := s.updatePwInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(err, op)
@@ -622,7 +624,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update account but no error returned from repository.")
}
out = a
case auth.OidcSubtype:
case oidc.Subtype:
a, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(err, op)
@@ -640,13 +642,13 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var err error
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
repo, iErr := s.pwRepoFn()
if iErr != nil {
return false, iErr
}
rows, err = repo.DeleteAccount(ctx, scopeId, id)
case auth.OidcSubtype:
case oidc.Subtype:
repo, iErr := s.oidcRepoFn()
if iErr != nil {
return false, iErr
@@ -667,7 +669,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
var outUl []auth.Account
switch auth.SubtypeFromId(authMethodId) {
case auth.PasswordSubtype:
case password.Subtype:
pwRepo, err := s.pwRepoFn()
if err != nil {
return nil, errors.Wrap(err, op)
@@ -679,7 +681,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
for _, a := range pwl {
outUl = append(outUl, a)
}
case auth.OidcSubtype:
case oidc.Subtype:
oidcRepo, err := s.oidcRepoFn()
if err != nil {
return nil, errors.Wrap(err, op)
@@ -742,8 +744,8 @@ func (s Service) setPasswordInRepo(ctx context.Context, scopeId, id string, vers
return out, nil
}
func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Type) (auth.AuthMethod, auth.VerifyResults) {
res := auth.VerifyResults{}
func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Type) (auth.AuthMethod, requestauth.VerifyResults) {
res := requestauth.VerifyResults{}
pwRepo, err := s.pwRepoFn()
if err != nil {
res.Error = err
@@ -756,13 +758,13 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
var parentId string
opts := []auth.Option{auth.WithType(resource.Account), auth.WithAction(a)}
opts := []requestauth.Option{requestauth.WithType(resource.Account), requestauth.WithAction(a)}
switch a {
case action.List, action.Create:
parentId = id
default:
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
acct, err := pwRepo.LookupAccount(ctx, id)
if err != nil {
res.Error = err
@@ -773,7 +775,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = acct.GetAuthMethodId()
case auth.OidcSubtype:
case oidc.Subtype:
acct, err := oidcRepo.LookupAccount(ctx, id)
if err != nil {
res.Error = err
@@ -785,12 +787,12 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
parentId = acct.GetAuthMethodId()
}
opts = append(opts, auth.WithId(id))
opts = append(opts, requestauth.WithId(id))
}
var authMeth auth.AuthMethod
switch auth.SubtypeFromId(parentId) {
case auth.PasswordSubtype:
case password.Subtype:
am, err := pwRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -801,7 +803,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
authMeth = am
case auth.OidcSubtype:
case oidc.Subtype:
am, err := oidcRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -813,8 +815,8 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
authMeth = am
}
opts = append(opts, auth.WithScopeId(authMeth.GetScopeId()), auth.WithPin(parentId))
return authMeth, auth.Verify(ctx, opts...)
opts = append(opts, requestauth.WithScopeId(authMeth.GetScopeId()), requestauth.WithPin(parentId))
return authMeth, requestauth.Verify(ctx, opts...)
}
func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.Account, error) {
@@ -860,7 +862,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
switch i := in.(type) {
case *password.Account:
if outputFields.Has(globals.TypeField) {
out.Type = auth.PasswordSubtype.String()
out.Type = password.Subtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -872,7 +874,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
out.Attributes = st
case *oidc.Account:
if outputFields.Has(globals.TypeField) {
out.Type = auth.OidcSubtype.String()
out.Type = oidc.Subtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -965,8 +967,8 @@ func validateCreateRequest(req *pbs.CreateAccountRequest) error {
badFields[authMethodIdField] = "This field is required."
}
switch auth.SubtypeFromId(req.GetItem().GetAuthMethodId()) {
case auth.PasswordSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.PasswordSubtype.String() {
case password.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
badFields[typeField] = "Doesn't match the parent resource's type."
}
attrs := &pb.PasswordAccountAttributes{}
@@ -976,8 +978,8 @@ func validateCreateRequest(req *pbs.CreateAccountRequest) error {
if attrs.GetLoginName() == "" {
badFields[loginNameKey] = "This is a required field for this type."
}
case auth.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.OidcSubtype.String() {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
badFields[typeField] = "Doesn't match the parent resource's type."
}
attrs := &pb.OidcAccountAttributes{}
@@ -1017,16 +1019,16 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch auth.SubtypeFromId(req.GetId()) {
case auth.PasswordSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.PasswordSubtype.String() {
case password.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
badFields[typeField] = "Cannot modify the resource type."
}
attrs := &pb.PasswordAccountAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
badFields[attributesField] = "Attribute fields do not match the expected format."
}
case auth.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.OidcSubtype.String() {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
badFields[typeField] = "Cannot modify the resource type."
}
attrs := &pb.OidcAccountAttributes{}
@@ -21,6 +21,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
requestauth "github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/accounts"
@@ -134,7 +135,7 @@ func TestGet(t *testing.T) {
UpdatedTime: pwA.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: org.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: "password",
Type: password.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{"login_name": structpb.NewStringValue(pwA.GetLoginName())}},
AuthorizedActions: pwAuthorizedActions,
}
@@ -159,7 +160,7 @@ func TestGet(t *testing.T) {
UpdatedTime: oidcA.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: org.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue(oidcAm.GetIssuer()),
"subject": structpb.NewStringValue("test-subject"),
@@ -219,7 +220,7 @@ func TestGet(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
if auth.SubtypeFromId(tc.req.Id) == auth.OidcSubtype {
if auth.SubtypeFromId(tc.req.Id) == oidc.Subtype {
// Set up managed groups before getting. First get the current
// managed group to make sure we have the right version.
oidcRepo, err := oidcRepoFn()
@@ -230,7 +231,7 @@ func TestGet(t *testing.T) {
require.NoError(err)
}
got, gErr := s.GetAccount(auth.DisabledAuthTestContext(iamRepoFn, org.GetPublicId()), tc.req)
got, gErr := s.GetAccount(requestauth.DisabledAuthTestContext(iamRepoFn, org.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "GetAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -348,7 +349,7 @@ func TestListPassword(t *testing.T) {
require.NoError(err, "Couldn't create new user service.")
// Test non-anon first
got, gErr := s.ListAccounts(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.ListAccounts(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "ListAccounts() with auth method %q got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -362,7 +363,7 @@ func TestListPassword(t *testing.T) {
if tc.skipAnon {
return
}
got, gErr = s.ListAccounts(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId(), auth.WithUserId(auth.AnonymousUserId)), tc.req)
got, gErr = s.ListAccounts(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId(), requestauth.WithUserId(requestauth.AnonymousUserId)), tc.req)
require.NoError(gErr)
assert.Len(got.Items, len(tc.res.Items))
for _, g := range got.GetItems() {
@@ -412,7 +413,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue(amSomeAccounts.GetIssuer()),
"subject": structpb.NewStringValue(subId),
@@ -432,7 +433,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue(amOtherAccounts.GetIssuer()),
"subject": structpb.NewStringValue(subId),
@@ -497,7 +498,7 @@ func TestListOidc(t *testing.T) {
s, err := accounts.NewService(pwRepoFn, oidcRepoFn)
require.NoError(err, "Couldn't create new user service.")
got, gErr := s.ListAccounts(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.ListAccounts(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "ListAccounts() with auth method %q got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -515,7 +516,7 @@ func TestListOidc(t *testing.T) {
if tc.skipAnon {
return
}
got, gErr = s.ListAccounts(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId(), auth.WithUserId(auth.AnonymousUserId)), tc.req)
got, gErr = s.ListAccounts(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId(), requestauth.WithUserId(requestauth.AnonymousUserId)), tc.req)
require.NoError(gErr)
assert.Len(got.Items, len(tc.res.Items))
for _, g := range got.GetItems() {
@@ -613,7 +614,7 @@ func TestDelete(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, gErr := s.DeleteAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.DeleteAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "DeleteAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -648,9 +649,9 @@ func TestDelete_twice(t *testing.T) {
req := &pbs.DeleteAccountRequest{
Id: ac.GetPublicId(),
}
_, gErr := s.DeleteAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
_, gErr := s.DeleteAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
assert.NoError(gErr, "First attempt")
_, gErr = s.DeleteAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
_, gErr = s.DeleteAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
assert.Error(gErr, "Second attempt")
assert.True(errors.Is(gErr, handlers.ApiErrorWithCode(codes.NotFound)), "Expected not found for the second delete.")
}
@@ -830,7 +831,7 @@ func TestCreatePassword(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, gErr := s.CreateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.CreateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "CreateAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -906,7 +907,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr("valid-account"),
},
},
@@ -918,7 +919,7 @@ func TestCreateOidc(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr("valid-account")
a.Fields["issuer"] = structpb.NewStringValue(am.GetIssuer())
@@ -942,7 +943,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr("no type defined")
a.Fields["issuer"] = structpb.NewStringValue(am.GetIssuer())
@@ -958,7 +959,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "overwritten issuer"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr("overwritten-issuer")
a.Fields["issuer"] = structpb.NewStringValue("https://overwrite.com")
@@ -973,7 +974,7 @@ func TestCreateOidc(t *testing.T) {
Name: &wrapperspb.StringValue{Value: "overwritten issuer"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr("overwritten-issuer")
a.Fields["issuer"] = structpb.NewStringValue("https://overwrite.com")
@@ -988,7 +989,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
Attributes: createAttr("cant-specify-mismatching-type"),
},
},
@@ -1001,7 +1002,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Id: oidc.AccountPrefix + "_notallowed",
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr("cant-specify-id"),
},
},
@@ -1014,7 +1015,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr("cant-specify-created-time"),
},
},
@@ -1027,7 +1028,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr("cant-specify-update-time"),
},
},
@@ -1039,7 +1040,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: nil,
@@ -1049,7 +1050,7 @@ func TestCreateOidc(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, gErr := s.CreateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.CreateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "CreateAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -1099,7 +1100,7 @@ func TestUpdatePassword(t *testing.T) {
freshAccount := func(t *testing.T) (*pb.Account, func()) {
t.Helper()
acc, err := tested.CreateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
acc, err := tested.CreateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
&pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
@@ -1113,7 +1114,7 @@ func TestUpdatePassword(t *testing.T) {
require.NoError(t, err)
clean := func() {
_, err := tested.DeleteAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
_, err := tested.DeleteAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
&pbs.DeleteAccountRequest{Id: acc.GetItem().GetId()})
require.NoError(t, err)
}
@@ -1417,7 +1418,7 @@ func TestUpdatePassword(t *testing.T) {
tc.res.Item.CreatedTime = acc.GetCreatedTime()
}
got, gErr := tested.UpdateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := tested.UpdateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "UpdateAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -1494,7 +1495,7 @@ func TestUpdateOidc(t *testing.T) {
acc := oidc.TestAccount(t, conn, am, "test-subject", oidc.WithName("default"), oidc.WithDescription("default"))
clean := func() {
_, err := tested.DeleteAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
_, err := tested.DeleteAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()),
&pbs.DeleteAccountRequest{Id: acc.GetPublicId()})
require.NoError(t, err)
}
@@ -1517,7 +1518,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -1525,7 +1526,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1541,7 +1542,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -1549,7 +1550,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1619,7 +1620,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1643,7 +1644,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1667,7 +1668,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1800,7 +1801,7 @@ func TestUpdateOidc(t *testing.T) {
tc.res.Item.CreatedTime = acc.GetCreateTime().GetTimestamp()
}
got, gErr := tested.UpdateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := tested.UpdateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "UpdateAccount(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -1861,7 +1862,7 @@ func TestSetPassword(t *testing.T) {
}
attrs, err := handlers.ProtoToStruct(pwAttrs)
require.NoError(t, err)
createResp, err := tested.CreateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.CreateAccountRequest{
createResp, err := tested.CreateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: "password",
@@ -1901,7 +1902,7 @@ func TestSetPassword(t *testing.T) {
assert, require := assert.New(t), require.New(t)
acct := createAccount(t, tt.oldPw)
setResp, err := tested.SetPassword(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.SetPasswordRequest{
setResp, err := tested.SetPassword(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.SetPasswordRequest{
Id: acct.GetId(),
Version: acct.GetVersion(),
Password: tt.newPw,
@@ -1959,7 +1960,7 @@ func TestSetPassword(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
setResp, err := tested.SetPassword(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.SetPasswordRequest{
setResp, err := tested.SetPassword(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.SetPasswordRequest{
Id: tt.accountId,
Version: tt.version,
Password: tt.password,
@@ -1999,7 +2000,7 @@ func TestChangePassword(t *testing.T) {
}
attrs, err := handlers.ProtoToStruct(pwAttrs)
require.NoError(t, err)
createResp, err := tested.CreateAccount(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.CreateAccountRequest{
createResp, err := tested.CreateAccount(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: "password",
@@ -2016,7 +2017,7 @@ func TestChangePassword(t *testing.T) {
assert, require := assert.New(t), require.New(t)
acct := createAccount(t, "originalpassword")
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
changeResp, err := tested.ChangePassword(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
Id: acct.GetId(),
Version: acct.GetVersion(),
CurrentPassword: "originalpassword",
@@ -2035,7 +2036,7 @@ func TestChangePassword(t *testing.T) {
assert := assert.New(t)
acct := createAccount(t, "originalpassword")
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
changeResp, err := tested.ChangePassword(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
Id: acct.GetId(),
Version: acct.GetVersion(),
CurrentPassword: "thewrongpassword",
@@ -2132,7 +2133,7 @@ func TestChangePassword(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
changeResp, err := tested.ChangePassword(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), &pbs.ChangePasswordRequest{
Id: tt.accountId,
Version: tt.version,
CurrentPassword: tt.oldPW,
@@ -5,7 +5,6 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/accounts"
@@ -38,7 +37,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "mismatched pw authmethod oidc type",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
@@ -46,7 +45,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "mismatched oidc authmethod pw type",
item: &pb.Account{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
@@ -54,7 +53,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing oidc subject",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
},
errContains: fieldError(subjectField, "This is a required field for this type."),
@@ -62,7 +61,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only name claim field",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"full_name": structpb.NewStringValue("something"),
@@ -73,7 +72,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only email claim field",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue("something"),
@@ -84,7 +83,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing login name for password type",
item: &pb.Account{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
},
errContains: fieldError(loginNameKey, "This is a required field for this type."),
@@ -92,7 +91,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "bad pw attributes",
item: &pb.Account{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"test": structpb.NewStringValue("something"),
@@ -103,7 +102,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "bad oidc attributes",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"test": structpb.NewStringValue("something"),
@@ -114,7 +113,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no error",
item: &pb.Account{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
loginNameKey: structpb.NewStringValue("something"),
@@ -124,7 +123,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no oidc errors",
item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"subject": structpb.NewStringValue("no oidc errors"),
@@ -159,7 +158,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: intglobals.OldPasswordAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -169,7 +168,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: intglobals.NewPasswordAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -179,7 +178,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "_1234567890",
Item: &pb.Account{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -251,7 +250,7 @@ func TestValidateUpdateRequest(t *testing.T) {
nameClaimField,
}
err := validateUpdateRequest(&pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "1234567890",
Id: oidc.AccountPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: readOnlyFields},
})
@@ -269,7 +268,7 @@ func TestValidateUpdateRequest(t *testing.T) {
subjectField,
}
err := validateUpdateRequest(&pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "1234567890",
Id: oidc.AccountPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: readOnlyFields},
})
@@ -19,6 +19,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
requestauth "github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -27,6 +28,7 @@ import (
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-secure-stdlib/strutil"
"google.golang.org/grpc/codes"
@@ -49,7 +51,7 @@ const (
var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = make(map[auth.Subtype]action.ActionSet)
IdActions = make(map[subtypes.Subtype]action.ActionSet)
// CollectionActions contains the set of actions that can be performed on
// this collection
@@ -151,7 +153,7 @@ func (s Service) ListAuthMethods(ctx context.Context, req *pbs.ListAuthMethodsRe
for _, am := range ul {
res.Id = am.GetPublicId()
res.ScopeId = am.GetScopeId()
authorizedActions := authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())], auth.WithResource(&res)).Strings()
authorizedActions := authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())], requestauth.WithResource(&res)).Strings()
if len(authorizedActions) == 0 {
continue
}
@@ -166,7 +168,7 @@ func (s Service) ListAuthMethods(ctx context.Context, req *pbs.ListAuthMethodsRe
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
if err != nil {
return nil, err
}
@@ -215,7 +217,7 @@ func (s Service) GetAuthMethod(ctx context.Context, req *pbs.GetAuthMethodReques
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
if err != nil {
return nil, err
}
@@ -260,7 +262,7 @@ func (s Service) CreateAuthMethod(ctx context.Context, req *pbs.CreateAuthMethod
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
if err != nil {
return nil, err
}
@@ -310,7 +312,7 @@ func (s Service) UpdateAuthMethod(ctx context.Context, req *pbs.UpdateAuthMethod
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
if err != nil {
return nil, err
}
@@ -364,7 +366,7 @@ func (s Service) ChangeState(ctx context.Context, req *pbs.ChangeStateRequest) (
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
if err != nil {
return nil, err
}
@@ -403,11 +405,11 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
}
switch auth.SubtypeFromId(req.GetAuthMethodId()) {
case auth.PasswordSubtype:
case password.Subtype:
if err := validateAuthenticatePasswordRequest(req); err != nil {
return nil, err
}
case auth.OidcSubtype:
case oidc.Subtype:
if err := validateAuthenticateOidcRequest(req); err != nil {
return nil, err
}
@@ -419,10 +421,10 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
}
switch auth.SubtypeFromId(req.GetAuthMethodId()) {
case auth.PasswordSubtype:
case password.Subtype:
return s.authenticatePassword(ctx, req, &authResults)
case auth.OidcSubtype:
case oidc.Subtype:
return s.authenticateOidc(ctx, req, &authResults)
}
return nil, errors.New(errors.Internal, op, "Invalid auth method subtype not caught in validation function.")
@@ -446,7 +448,7 @@ func (s Service) AuthenticateLogin(ctx context.Context, req *pbs.AuthenticateLog
ScopeId: authResults.Scope.Id,
Type: resource.AuthToken,
}
tok.AuthorizedActions = authResults.FetchActionSetForId(ctx, tok.Id, authtokens.IdActions, auth.WithResource(res)).Strings()
tok.AuthorizedActions = authResults.FetchActionSetForId(ctx, tok.Id, authtokens.IdActions, requestauth.WithResource(res)).Strings()
return &pbs.AuthenticateLoginResponse{Item: tok, TokenType: req.GetTokenType()}, nil
}
@@ -454,14 +456,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.AuthMethod, e
var lookupErr error
var am auth.AuthMethod
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
repo, err := s.pwRepoFn()
if err != nil {
return nil, err
}
am, lookupErr = repo.LookupAuthMethod(ctx, id)
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, err
@@ -485,7 +487,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.AuthMethod, e
return am, nil
}
func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResults auth.VerifyResults) ([]auth.AuthMethod, error) {
func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResults requestauth.VerifyResults) ([]auth.AuthMethod, error) {
const op = "authmethods.(Service).listFromRepo"
reqCtx, ok := requests.RequestContextFromCtx(ctx)
if !ok {
@@ -498,7 +500,7 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResult
if err != nil {
return nil, errors.Wrap(err, op)
}
ol, err := oidcRepo.ListAuthMethods(ctx, scopeIds, oidc.WithUnauthenticatedUser(reqCtx.UserId == auth.AnonymousUserId))
ol, err := oidcRepo.ListAuthMethods(ctx, scopeIds, oidc.WithUnauthenticatedUser(reqCtx.UserId == requestauth.AnonymousUserId))
if err != nil {
return nil, errors.Wrap(err, op)
}
@@ -524,7 +526,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
const op = "authmethods.(Service).createInRepo"
var out auth.AuthMethod
switch auth.SubtypeFromType(item.GetType()) {
case auth.PasswordSubtype:
case password.Subtype:
am, err := s.createPwInRepo(ctx, scopeId, item)
if err != nil {
return nil, errors.Wrap(err, op)
@@ -533,7 +535,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create auth method but no error returned from repository.")
}
out = am
case auth.OidcSubtype:
case oidc.Subtype:
am, err := s.createOidcInRepo(ctx, scopeId, item)
if err != nil {
return nil, errors.Wrap(err, op)
@@ -553,7 +555,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
var dryRun bool
switch auth.SubtypeFromId(req.GetId()) {
case auth.PasswordSubtype:
case password.Subtype:
pam, err := s.updatePwInRepo(ctx, scopeId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, false, errors.Wrap(err, op)
@@ -563,7 +565,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
}
am = pam
case auth.OidcSubtype:
case oidc.Subtype:
oam, dr, err := s.updateOidcInRepo(ctx, scopeId, req)
if err != nil {
return nil, false, errors.Wrap(err, op)
@@ -583,14 +585,14 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var dErr error
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
repo, err := s.pwRepoFn()
if err != nil {
return false, errors.Wrap(err, op)
}
rows, dErr = repo.DeleteAuthMethod(ctx, scopeId, id)
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
return false, errors.Wrap(err, op)
@@ -612,7 +614,7 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
const op = "authmethod_service.(Service).changeStateInRepo"
switch auth.SubtypeFromId(req.GetId()) {
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, err
@@ -649,12 +651,12 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
return nil, errors.New(errors.InvalidParameter, op, "Given auth method type does not support changing state")
}
func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.VerifyResults {
func (s Service) authResult(ctx context.Context, id string, a action.Type) requestauth.VerifyResults {
const op = "authmethods.(Service).authResult"
res := auth.VerifyResults{}
res := requestauth.VerifyResults{}
var parentId string
opts := []auth.Option{auth.WithType(resource.AuthMethod), auth.WithAction(a)}
opts := []requestauth.Option{requestauth.WithType(resource.AuthMethod), requestauth.WithAction(a)}
switch a {
case action.List, action.Create:
parentId = id
@@ -675,7 +677,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
default:
var authMeth auth.AuthMethod
switch auth.SubtypeFromId(id) {
case auth.PasswordSubtype:
case password.Subtype:
repo, err := s.pwRepoFn()
if err != nil {
res.Error = err
@@ -691,7 +693,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return res
}
authMeth = am
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
res.Error = err
@@ -712,10 +714,10 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return res
}
parentId = authMeth.GetScopeId()
opts = append(opts, auth.WithId(id))
opts = append(opts, requestauth.WithId(id))
}
opts = append(opts, auth.WithScopeId(parentId))
return auth.Verify(ctx, opts...)
opts = append(opts, requestauth.WithScopeId(parentId))
return requestauth.Verify(ctx, opts...)
}
func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.Option) (*pb.AuthMethod, error) {
@@ -762,7 +764,7 @@ func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.
switch i := in.(type) {
case *password.AuthMethod:
if outputFields.Has(globals.TypeField) {
out.Type = auth.PasswordSubtype.String()
out.Type = password.Subtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -777,7 +779,7 @@ func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.
out.Attributes = st
case *oidc.AuthMethod:
if outputFields.Has(globals.TypeField) {
out.Type = auth.OidcSubtype.String()
out.Type = oidc.Subtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -861,12 +863,12 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
badFields[isPrimaryField] = "This field is read only."
}
switch auth.SubtypeFromType(req.GetItem().GetType()) {
case auth.PasswordSubtype:
case password.Subtype:
attrs := &pb.PasswordAuthMethodAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
badFields[attributesField] = "Attribute fields do not match the expected format."
}
case auth.OidcSubtype:
case oidc.Subtype:
attrs := &pb.OidcAuthMethodAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
badFields[attributesField] = "Attribute fields do not match the expected format."
@@ -942,7 +944,7 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
}
}
default:
badFields[typeField] = fmt.Sprintf("This is a required field and must be %q.", auth.PasswordSubtype.String())
badFields[typeField] = fmt.Sprintf("This is a required field and must be %q.", password.Subtype.String())
}
return badFields
})
@@ -959,16 +961,16 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
badFields[isPrimaryField] = "This field is read only."
}
switch auth.SubtypeFromId(req.GetId()) {
case auth.PasswordSubtype:
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != auth.PasswordSubtype {
case password.Subtype:
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != password.Subtype {
badFields[typeField] = "Cannot modify the resource type."
}
attrs := &pb.PasswordAuthMethodAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
badFields[attributesField] = "Attribute fields do not match the expected format."
}
case auth.OidcSubtype:
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != auth.OidcSubtype {
case oidc.Subtype:
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != oidc.Subtype {
badFields[typeField] = "Cannot modify the resource type."
}
attrs := &pb.OidcAuthMethodAttributes{}
@@ -1111,8 +1113,8 @@ func validateChangeStateRequest(req *pbs.ChangeStateRequest) error {
if req == nil {
return errors.New(errors.InvalidParameter, op, "Missing request")
}
if st := auth.SubtypeFromId(req.GetId()); st != auth.OidcSubtype {
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", auth.OidcSubtype.String())
if st := auth.SubtypeFromId(req.GetId()); st != oidc.Subtype {
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", oidc.Subtype.String())
}
badFields := make(map[string]string)
if req.GetVersion() == 0 {
@@ -1147,7 +1149,7 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
} else {
st := auth.SubtypeFromId(req.GetAuthMethodId())
switch st {
case auth.PasswordSubtype, auth.OidcSubtype:
case password.Subtype, oidc.Subtype:
default:
badFields[authMethodIdField] = "Unknown auth method type."
}
@@ -1234,7 +1236,7 @@ func (s Service) ConvertInternalAuthTokenToApiAuthToken(ctx context.Context, tok
return prot, nil
}
func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.AuthenticateRequest, authResults *auth.VerifyResults, tok *pba.AuthToken) (*pbs.AuthenticateResponse, error) {
func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.AuthenticateRequest, authResults *requestauth.VerifyResults, tok *pba.AuthToken) (*pbs.AuthenticateResponse, error) {
const op = "authmethod.convertToAuthenticateResponse"
if req == nil {
return nil, errors.New(errors.InvalidParameter, op, "Missing request.")
@@ -1255,7 +1257,7 @@ func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.Aut
ScopeId: authResults.Scope.Id,
Type: resource.AuthToken,
}
tok.AuthorizedActions = authResults.FetchActionSetForId(ctx, tok.Id, authtokens.IdActions, auth.WithResource(res)).Strings()
tok.AuthorizedActions = authResults.FetchActionSetForId(ctx, tok.Id, authtokens.IdActions, requestauth.WithResource(res)).Strings()
retAttrs, err := handlers.ProtoToStruct(tok)
if err != nil {
return nil, err
@@ -9,7 +9,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
@@ -20,6 +19,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
requestauth "github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authmethods"
"github.com/hashicorp/boundary/internal/types/action"
@@ -120,7 +120,7 @@ func TestGet(t *testing.T) {
ScopeId: oidcam.GetScopeId(),
CreatedTime: oidcam.CreateTime.GetTimestamp(),
UpdatedTime: oidcam.UpdateTime.GetTimestamp(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://alice.com"),
"client_id": structpb.NewStringValue("alice_rp"),
@@ -187,7 +187,7 @@ func TestGet(t *testing.T) {
s, err := authmethods.NewService(kmsCache, pwRepoFn, oidcRepoFn, iamRepoFn, atRepoFn)
require.NoError(err, "Couldn't create new auth_method service.")
got, gErr := s.GetAuthMethod(auth.DisabledAuthTestContext(iamRepoFn, tc.scopeId), tc.req)
got, gErr := s.GetAuthMethod(requestauth.DisabledAuthTestContext(iamRepoFn, tc.scopeId), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "GetAuthMethod(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -240,7 +240,7 @@ func TestList(t *testing.T) {
UpdatedTime: oidcam.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: oWithAuthMethods.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 2,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://alice.com"),
"client_id": structpb.NewStringValue("alice_rp"),
@@ -354,7 +354,7 @@ func TestList(t *testing.T) {
require.NoError(err, "Couldn't create new auth_method service.")
// First check with non-anonymous user
got, gErr := s.ListAuthMethods(auth.DisabledAuthTestContext(iamRepoFn, tc.req.GetScopeId()), tc.req)
got, gErr := s.ListAuthMethods(requestauth.DisabledAuthTestContext(iamRepoFn, tc.req.GetScopeId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "ListAuthMethods() for scope %q got error %v, wanted %v", tc.req.GetScopeId(), gErr, tc.err)
@@ -371,7 +371,7 @@ func TestList(t *testing.T) {
assert.Empty(cmp.Diff(got, tc.res, protocmp.Transform()), "ListAuthMethods() for scope %q got response %q, wanted %q", tc.req.GetScopeId(), got, tc.res)
// Now check with anonymous user
got, gErr = s.ListAuthMethods(auth.DisabledAuthTestContext(iamRepoFn, tc.req.GetScopeId(), auth.WithUserId(auth.AnonymousUserId)), tc.req)
got, gErr = s.ListAuthMethods(requestauth.DisabledAuthTestContext(iamRepoFn, tc.req.GetScopeId(), requestauth.WithUserId(requestauth.AnonymousUserId)), tc.req)
require.NoError(gErr)
assert.Len(got.Items, len(tc.res.Items))
for _, g := range got.GetItems() {
@@ -450,7 +450,7 @@ func TestDelete(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, gErr := s.DeleteAuthMethod(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
got, gErr := s.DeleteAuthMethod(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "DeleteAuthMethod(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -489,9 +489,9 @@ func TestDelete_twice(t *testing.T) {
req := &pbs.DeleteAuthMethodRequest{
Id: am.GetPublicId(),
}
_, gErr := s.DeleteAuthMethod(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
_, gErr := s.DeleteAuthMethod(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
assert.NoError(gErr, "First attempt")
_, gErr = s.DeleteAuthMethod(auth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
_, gErr = s.DeleteAuthMethod(requestauth.DisabledAuthTestContext(iamRepoFn, o.GetPublicId()), req)
assert.Error(gErr, "Second attempt")
assert.True(errors.Is(gErr, handlers.ApiErrorWithCode(codes.NotFound)), "Expected permission denied for the second delete.")
}
@@ -560,7 +560,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid OIDC AuthMethod",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -590,7 +590,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: o.GetType(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -650,7 +650,7 @@ func TestCreate(t *testing.T) {
name: "Create a global OIDC AuthMethod",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: scope.Global.String(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://example.discovery.url"),
"api_url_prefix": structpb.NewStringValue("https://api.com"),
@@ -668,7 +668,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url"),
@@ -696,7 +696,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -706,7 +706,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -715,7 +715,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify IsPrimary",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
IsPrimary: true,
}},
res: nil,
@@ -726,7 +726,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -747,7 +747,7 @@ func TestCreate(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "Attributes must be valid for type"},
Description: &wrapperspb.StringValue{Value: "Attributes must be valid for type"},
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"invalid_field": structpb.NewStringValue("invalid_value"),
"min_login_name_length": structpb.NewNumberValue(3),
@@ -762,7 +762,7 @@ func TestCreate(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "Attributes must be valid for type"},
Description: &wrapperspb.StringValue{Value: "Attributes must be valid for type"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"login-name": structpb.NewStringValue("invalid_value"),
"password": structpb.NewNumberValue(3),
@@ -775,7 +775,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Doesn't Require Issuer",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -791,7 +791,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: o.GetType(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -807,7 +807,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires ApiUrl",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"client_id": structpb.NewStringValue("someclientid"),
"client_secret": structpb.NewStringValue("secret"),
@@ -819,7 +819,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires Client Id",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -832,7 +832,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires Client Secret",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -845,7 +845,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify client secret hmac",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -860,7 +860,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify state",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -875,7 +875,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Must Match Standard Alg Names",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example2.discovery.url:4821"),
@@ -893,7 +893,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod API Urls Prefix Format",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://example2.discovery.url:4821"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -907,7 +907,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Callback Url Read Only",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue("https://example2.discovery.url:4821"),
"client_id": structpb.NewStringValue("someclientid"),
@@ -921,7 +921,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod unparseable certificates",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example2.discovery.url:4821"),
@@ -939,7 +939,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify default claims scopes of openid",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"api_url_prefix": structpb.NewStringValue("https://api.com"),
"issuer": structpb.NewStringValue("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -961,7 +961,7 @@ func TestCreate(t *testing.T) {
s, err := authmethods.NewService(kms, pwRepoFn, oidcRepoFn, iamRepoFn, atRepoFn)
require.NoError(err, "Error when getting new auth_method service.")
got, gErr := s.CreateAuthMethod(auth.DisabledAuthTestContext(iamRepoFn, tc.req.GetItem().GetScopeId()), tc.req)
got, gErr := s.CreateAuthMethod(requestauth.DisabledAuthTestContext(iamRepoFn, tc.req.GetItem().GetScopeId()), tc.req)
if tc.err != nil {
require.Error(gErr)
assert.True(errors.Is(gErr, tc.err), "CreateAuthMethod(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
@@ -7,12 +7,12 @@ import (
"net/url"
"strings"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
oidcstore "github.com/hashicorp/boundary/internal/auth/oidc/store"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authmethods"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"google.golang.org/grpc/codes"
@@ -53,7 +53,7 @@ func init() {
panic(err)
}
IdActions[auth.OidcSubtype] = action.ActionSet{
IdActions[oidc.Subtype] = action.ActionSet{
action.NoOp,
action.Read,
action.Update,
@@ -13,7 +13,6 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
@@ -26,6 +25,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authmethods"
@@ -305,7 +305,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: wrapperspb.String("default"),
Description: wrapperspb.String("default"),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultAttributeFields(),
},
@@ -345,7 +345,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -353,7 +353,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -372,7 +372,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -380,7 +380,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -412,7 +412,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -484,7 +484,7 @@ func TestUpdate_OIDC(t *testing.T) {
UpdateMask: &field_mask.FieldMask{Paths: []string{"name", "type"}},
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "updated name"},
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
},
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -513,7 +513,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -537,7 +537,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -563,7 +563,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -589,7 +589,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: defaultReadAttributeFields(),
},
@@ -661,7 +661,7 @@ func TestUpdate_OIDC(t *testing.T) {
Paths: []string{"type"},
},
Item: &pb.AuthMethod{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: nil,
@@ -716,7 +716,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -749,7 +749,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -782,7 +782,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -830,7 +830,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -867,7 +867,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -906,7 +906,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -945,7 +945,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -1037,7 +1037,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{
Fields: func() map[string]*structpb.Value {
f := defaultReadAttributeFields()
@@ -1172,7 +1172,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
CreatedTime: am.GetCreateTime().GetTimestamp(),
UpdatedTime: am.GetUpdateTime().GetTimestamp(),
Version: am.GetVersion(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthorizedActions: oidcAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions,
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
@@ -1353,7 +1353,7 @@ func TestChangeState_OIDC(t *testing.T) {
ScopeId: oidcam.GetScopeId(),
CreatedTime: oidcam.CreateTime.GetTimestamp(),
UpdatedTime: oidcam.UpdateTime.GetTimestamp(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"issuer": structpb.NewStringValue(oidcam.GetIssuer()),
"client_id": structpb.NewStringValue(tpClientId),
@@ -5,13 +5,13 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/password"
pwstore "github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authmethods"
pba "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"google.golang.org/grpc/codes"
@@ -32,7 +32,7 @@ func init() {
panic(err)
}
IdActions[auth.PasswordSubtype] = action.ActionSet{
IdActions[password.Subtype] = action.ActionSet{
action.NoOp,
action.Read,
action.Update,
@@ -6,7 +6,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
@@ -18,6 +17,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authmethods"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -5,13 +5,13 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -8,7 +8,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
@@ -18,6 +17,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authtokens"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -6,7 +6,6 @@ import (
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/credential/vault/store"
@@ -15,6 +14,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
@@ -379,7 +379,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
opts = append(opts, auth.WithId(id))
switch credential.SubtypeFromId(id) {
case credential.VaultSubtype:
case vault.Subtype:
cl, err := repo.LookupCredentialLibrary(ctx, id)
if err != nil {
res.Error = err
@@ -404,7 +404,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
opts = append(opts, auth.WithPin(parentId))
switch credential.SubtypeFromId(parentId) {
case credential.VaultSubtype:
case vault.Subtype:
cs, err := repo.LookupCredentialStore(ctx, parentId)
if err != nil {
res.Error = err
@@ -465,7 +465,7 @@ func toProto(in credential.Library, opt ...handlers.Option) (*pb.CredentialLibra
}
if outputFields.Has(globals.AttributesField) {
switch credential.SubtypeFromId(in.GetPublicId()) {
case credential.VaultSubtype:
case vault.Subtype:
vaultIn, ok := in.(*vault.CredentialLibrary)
if !ok {
return nil, errors.New(errors.Internal, op, "unable to cast to vault credential library")
@@ -531,8 +531,8 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch credential.SubtypeFromId(req.GetItem().GetCredentialStoreId()) {
case credential.VaultSubtype:
if t := req.GetItem().GetType(); t != "" && credential.SubtypeFromType(t) != credential.VaultSubtype {
case vault.Subtype:
if t := req.GetItem().GetType(); t != "" && credential.SubtypeFromType(t) != vault.Subtype {
badFields[globals.CredentialStoreIdField] = "If included, type must match that of the credential store."
}
attrs := &pb.VaultCredentialLibraryAttributes{}
@@ -560,8 +560,8 @@ func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch credential.SubtypeFromId(req.GetId()) {
case credential.VaultSubtype:
if req.GetItem().GetType() != "" && credential.SubtypeFromType(req.GetItem().GetType()) != credential.VaultSubtype {
case vault.Subtype:
if req.GetItem().GetType() != "" && credential.SubtypeFromType(req.GetItem().GetType()) != vault.Subtype {
badFields[globals.TypeField] = "Cannot modify resource type."
}
attrs := &pb.VaultCredentialLibraryAttributes{}
@@ -7,8 +7,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -19,6 +17,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/assert"
@@ -63,7 +62,7 @@ func TestList(t *testing.T) {
CreatedTime: l.GetCreateTime().GetTimestamp(),
UpdatedTime: l.GetUpdateTime().GetTimestamp(),
Version: l.GetVersion(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialLibraryAttributes{
@@ -251,7 +250,7 @@ func TestCreate(t *testing.T) {
{
name: "parent id must be included",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -351,7 +350,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -391,7 +390,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -480,7 +479,7 @@ func TestGet(t *testing.T) {
Id: vl.GetPublicId(),
CredentialStoreId: vl.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: vl.CreateTime.GetTimestamp(),
UpdatedTime: vl.UpdateTime.GetTimestamp(),
@@ -7,7 +7,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/credential/vault/store"
@@ -16,6 +15,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -502,7 +502,7 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
}
if outputFields.Has(globals.AttributesField) {
switch credential.SubtypeFromId(in.GetPublicId()) {
case credential.VaultSubtype:
case vault.Subtype:
vaultIn, ok := in.(*vault.CredentialStore)
if !ok {
return nil, errors.New(errors.Internal, op, "unable to cast to vault credential store")
@@ -613,7 +613,7 @@ func validateCreateRequest(req *pbs.CreateCredentialStoreRequest) error {
badFields["scope_id"] = "This field must be a valid project scope id."
}
switch credential.SubtypeFromType(req.GetItem().GetType()) {
case credential.VaultSubtype:
case vault.Subtype:
attrs := &pb.VaultCredentialStoreAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
badFields[globals.AttributesField] = fmt.Sprintf("Attribute fields do not match the expected format. Got %#v", req.GetItem().GetAttributes().AsMap())
@@ -656,8 +656,8 @@ func validateUpdateRequest(req *pbs.UpdateCredentialStoreRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch credential.SubtypeFromId(req.GetId()) {
case credential.VaultSubtype:
if req.GetItem().GetType() != "" && credential.SubtypeFromType(req.GetItem().GetType()) != credential.VaultSubtype {
case vault.Subtype:
if req.GetItem().GetType() != "" && credential.SubtypeFromType(req.GetItem().GetType()) != vault.Subtype {
badFields["type"] = "Cannot modify resource type."
}
attrs := &pb.VaultCredentialStoreAttributes{}
@@ -10,8 +10,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -22,6 +20,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/assert"
@@ -64,7 +63,7 @@ func TestList(t *testing.T) {
CreatedTime: s.GetCreateTime().GetTimestamp(),
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
Version: s.GetVersion(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
@@ -186,7 +185,7 @@ func TestCreate(t *testing.T) {
name: "missing ca certificate",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -205,7 +204,7 @@ func TestCreate(t *testing.T) {
name: "Bad token",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -225,7 +224,7 @@ func TestCreate(t *testing.T) {
name: "Define only client cert",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -244,7 +243,7 @@ func TestCreate(t *testing.T) {
name: "Define only client cert key",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -263,7 +262,7 @@ func TestCreate(t *testing.T) {
name: "Define key in both client cert payload and key field",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -284,7 +283,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Id: vault.CredentialStorePrefix + "_notallowed",
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -302,7 +301,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -320,7 +319,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -338,7 +337,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -371,7 +370,7 @@ func TestCreate(t *testing.T) {
name: "Must specify vault VaultAddress",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Token: wrapperspb.String(newToken()),
@@ -387,7 +386,7 @@ func TestCreate(t *testing.T) {
name: "Must specify vault token",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -403,7 +402,7 @@ func TestCreate(t *testing.T) {
name: "Attributes must be valid for vault type",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -421,7 +420,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialStore with client cert and key in same field",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -440,7 +439,7 @@ func TestCreate(t *testing.T) {
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
CaCert: wrapperspb.String(string(v.CaCert)),
@@ -462,7 +461,7 @@ func TestCreate(t *testing.T) {
ScopeId: prj.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -484,7 +483,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
CaCert: wrapperspb.String(string(v.CaCert)),
@@ -584,7 +583,7 @@ func TestGet(t *testing.T) {
Id: store.GetPublicId(),
ScopeId: store.GetScopeId(),
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: store.CreateTime.GetTimestamp(),
UpdatedTime: store.UpdateTime.GetTimestamp(),
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/groups"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -13,6 +12,7 @@ import (
"github.com/hashicorp/boundary/internal/iam/store"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -8,12 +8,12 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/groups"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/groups"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostcatalogs"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -14,6 +13,7 @@ import (
"github.com/hashicorp/boundary/internal/host/static/store"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -473,7 +473,7 @@ func toProto(ctx context.Context, in *static.HostCatalog, opt ...handlers.Option
out.ScopeId = in.GetScopeId()
}
if outputFields.Has(globals.TypeField) {
out.Type = host.StaticSubtype.String()
out.Type = static.Subtype.String()
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
out.Description = wrapperspb.String(in.GetDescription())
@@ -520,9 +520,9 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
badFields["scope_id"] = "This field must be a valid project scope id."
}
switch host.SubtypeFromType(req.GetItem().GetType()) {
case host.StaticSubtype:
case static.Subtype:
default:
badFields["type"] = fmt.Sprintf("This is a required field and must be %q.", host.StaticSubtype.String())
badFields["type"] = fmt.Sprintf("This is a required field and must be %q.", static.Subtype.String())
}
return badFields
})
@@ -532,8 +532,8 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch host.SubtypeFromId(req.GetId()) {
case host.StaticSubtype:
if req.GetItem().GetType() != "" && host.SubtypeFromType(req.GetItem().GetType()) != host.StaticSubtype {
case static.Subtype:
if req.GetItem().GetType() != "" && host.SubtypeFromType(req.GetItem().GetType()) != static.Subtype {
badFields["type"] = "Cannot modify resource type."
}
}
@@ -9,7 +9,6 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostcatalogs"
scopepb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
@@ -17,6 +16,7 @@ import (
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/host_catalogs"
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostsets"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -14,6 +13,7 @@ import (
"github.com/hashicorp/boundary/internal/host/static/store"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
@@ -588,7 +588,7 @@ func toProto(ctx context.Context, in *static.HostSet, hosts []*static.Host, opt
out.HostCatalogId = in.GetCatalogId()
}
if outputFields.Has(globals.TypeField) {
out.Type = host.StaticSubtype.String()
out.Type = static.Subtype.String()
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
out.Description = &wrapperspb.StringValue{Value: in.GetDescription()}
@@ -637,8 +637,8 @@ func validateCreateRequest(req *pbs.CreateHostSetRequest) error {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
switch host.SubtypeFromId(req.GetItem().GetHostCatalogId()) {
case host.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != host.StaticSubtype.String() {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
badFields["type"] = "Doesn't match the parent resource's type."
}
}
@@ -650,8 +650,8 @@ func validateUpdateRequest(req *pbs.UpdateHostSetRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch host.SubtypeFromId(req.GetId()) {
case host.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != host.StaticSubtype.String() {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
badFields["type"] = "Cannot modify the resource type."
}
}
@@ -9,15 +9,14 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostsets"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/host"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/host_sets"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -151,7 +150,7 @@ func TestList(t *testing.T) {
CreatedTime: h.GetCreateTime().GetTimestamp(),
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
Version: h.GetVersion(),
Type: host.StaticSubtype.String(),
Type: static.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
})
}
@@ -7,7 +7,6 @@ import (
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hosts"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -16,10 +15,12 @@ import (
"github.com/hashicorp/boundary/internal/host/static/store"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/subtypes"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/types/known/wrapperspb"
)
@@ -427,7 +428,7 @@ func toProto(ctx context.Context, in *static.Host, hostSets []*static.HostSet, o
out.HostCatalogId = in.GetCatalogId()
}
if outputFields.Has(globals.TypeField) {
out.Type = host.StaticSubtype.String()
out.Type = static.Subtype.String()
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
out.Description = &wrapperspb.StringValue{Value: in.GetDescription()}
@@ -476,7 +477,7 @@ func validateGetRequest(req *pbs.GetHostRequest) error {
return handlers.ValidateGetRequest(func() map[string]string {
badFields := map[string]string{}
ct := host.SubtypeFromId(req.GetId())
if ct == host.UnknownSubtype {
if ct == subtypes.UnknownSubtype {
badFields["id"] = "Improperly formatted identifier used."
}
return badFields
@@ -490,8 +491,8 @@ func validateCreateRequest(req *pbs.CreateHostRequest) error {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
switch host.SubtypeFromId(req.GetItem().GetHostCatalogId()) {
case host.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != host.StaticSubtype.String() {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
badFields["type"] = "Doesn't match the parent resource's type."
}
attrs := &pb.StaticHostAttributes{}
@@ -521,8 +522,8 @@ func validateUpdateRequest(req *pbs.UpdateHostRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch host.SubtypeFromId(req.GetId()) {
case host.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != host.StaticSubtype.String() {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
badFields["type"] = "Cannot modify the resource type."
attrs := &pb.StaticHostAttributes{}
@@ -9,15 +9,14 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/hosts"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/host"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/hosts"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -144,7 +143,7 @@ func TestList(t *testing.T) {
CreatedTime: h.GetCreateTime().GetTimestamp(),
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
Version: h.GetVersion(),
Type: host.StaticSubtype.String(), Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
Type: static.Subtype.String(), Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"address": structpb.NewStringValue(h.GetAddress()),
}},
AuthorizedActions: testAuthorizedActions,
@@ -14,10 +14,12 @@ import (
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
requestauth "github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/hashicorp/go-bexpr"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/types/known/wrapperspb"
@@ -33,8 +35,8 @@ var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = map[auth.Subtype]action.ActionSet{
auth.OidcSubtype: {
IdActions = map[subtypes.Subtype]action.ActionSet{
oidc.Subtype: {
action.NoOp,
action.Read,
action.Update,
@@ -105,7 +107,7 @@ func (s Service) ListManagedGroups(ctx context.Context, req *pbs.ListManagedGrou
}
for _, mg := range ul {
res.Id = mg.GetPublicId()
authorizedActions := authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())], auth.WithResource(&res)).Strings()
authorizedActions := authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())], requestauth.WithResource(&res)).Strings()
if len(authorizedActions) == 0 {
continue
}
@@ -274,7 +276,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.ManagedGroup,
var out auth.ManagedGroup
var memberIds []string
switch auth.SubtypeFromId(id) {
case auth.OidcSubtype:
case oidc.Subtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, nil, err
@@ -346,7 +348,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
}
var out auth.ManagedGroup
switch auth.SubtypeFromId(am.GetPublicId()) {
case auth.OidcSubtype:
case oidc.Subtype:
am, err := s.createOidcInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(err, op)
@@ -406,7 +408,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
const op = "managed_groups.(Service).updateInRepo"
var out auth.ManagedGroup
switch auth.SubtypeFromId(req.GetId()) {
case auth.OidcSubtype:
case oidc.Subtype:
mg, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(err, op)
@@ -424,7 +426,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var err error
switch auth.SubtypeFromId(id) {
case auth.OidcSubtype:
case oidc.Subtype:
repo, iErr := s.oidcRepoFn()
if iErr != nil {
return false, iErr
@@ -445,7 +447,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
var outUl []auth.ManagedGroup
switch auth.SubtypeFromId(authMethodId) {
case auth.OidcSubtype:
case oidc.Subtype:
oidcRepo, err := s.oidcRepoFn()
if err != nil {
return nil, errors.Wrap(err, op)
@@ -461,8 +463,9 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
return outUl, nil
}
func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Type) (auth.AuthMethod, auth.VerifyResults) {
res := auth.VerifyResults{}
func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Type) (auth.AuthMethod, requestauth.VerifyResults) {
const op = "managed_groups.(Service)."
res := requestauth.VerifyResults{}
oidcRepo, err := s.oidcRepoFn()
if err != nil {
res.Error = err
@@ -470,13 +473,13 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
var parentId string
opts := []auth.Option{auth.WithType(resource.ManagedGroup), auth.WithAction(a)}
opts := []requestauth.Option{requestauth.WithType(resource.ManagedGroup), requestauth.WithAction(a)}
switch a {
case action.List, action.Create:
parentId = id
default:
switch auth.SubtypeFromId(id) {
case auth.OidcSubtype:
case oidc.Subtype:
acct, err := oidcRepo.LookupManagedGroup(ctx, id)
if err != nil {
res.Error = err
@@ -487,13 +490,16 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = acct.GetAuthMethodId()
default:
res.Error = errors.New(errors.InvalidPublicId, op, "unrecognized managed group subtype")
return nil, res
}
opts = append(opts, auth.WithId(id))
opts = append(opts, requestauth.WithId(id))
}
var authMeth auth.AuthMethod
switch auth.SubtypeFromId(parentId) {
case auth.OidcSubtype:
case oidc.Subtype:
am, err := oidcRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -504,9 +510,13 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
authMeth = am
opts = append(opts, requestauth.WithScopeId(am.GetScopeId()))
default:
res.Error = errors.New(errors.InvalidPublicId, op, "unrecognized auth method subtype")
return nil, res
}
opts = append(opts, auth.WithScopeId(authMeth.GetScopeId()), auth.WithPin(parentId))
return authMeth, auth.Verify(ctx, opts...)
opts = append(opts, requestauth.WithPin(parentId))
return authMeth, requestauth.Verify(ctx, opts...)
}
func toProto(ctx context.Context, in auth.ManagedGroup, opt ...handlers.Option) (*pb.ManagedGroup, error) {
@@ -550,7 +560,7 @@ func toProto(ctx context.Context, in auth.ManagedGroup, opt ...handlers.Option)
switch i := in.(type) {
case *oidc.ManagedGroup:
if outputFields.Has(globals.TypeField) {
out.Type = auth.OidcSubtype.String()
out.Type = oidc.Subtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -591,8 +601,8 @@ func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
badFields[globals.AuthMethodIdField] = "This field is required."
}
switch auth.SubtypeFromId(req.GetItem().GetAuthMethodId()) {
case auth.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.OidcSubtype.String() {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
attrs := &pb.OidcManagedGroupAttributes{}
@@ -621,8 +631,8 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch auth.SubtypeFromId(req.GetId()) {
case auth.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.OidcSubtype.String() {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
badFields[globals.TypeField] = "Cannot modify the resource type."
}
attrs := &pb.OidcManagedGroupAttributes{}
@@ -638,6 +648,8 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
}
}
}
default:
badFields[globals.IdField] = "Unrecognized resource type."
}
return badFields
}, intglobals.OidcManagedGroupPrefix)
@@ -11,8 +11,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/managedgroups"
@@ -21,6 +21,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/managed_groups"
@@ -213,7 +214,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"filter": structpb.NewStringValue(oidc.TestFakeManagedGroupFilter),
}},
@@ -232,7 +233,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"filter": structpb.NewStringValue(oidc.TestFakeManagedGroupFilter),
}},
@@ -483,7 +484,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr(),
},
},
@@ -495,7 +496,7 @@ func TestCreateOidc(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr()
a.Fields["filter"] = structpb.NewStringValue(oidc.TestFakeManagedGroupFilter)
@@ -519,7 +520,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr()
a.Fields["filter"] = structpb.NewStringValue(oidc.TestFakeManagedGroupFilter)
@@ -534,7 +535,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
Attributes: createAttr(),
},
},
@@ -547,7 +548,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Id: intglobals.OidcManagedGroupPrefix + "_notallowed",
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr(),
},
},
@@ -560,7 +561,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr(),
},
},
@@ -573,7 +574,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: createAttr(),
},
},
@@ -586,7 +587,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: func() *structpb.Struct {
a := createAttr()
a.Fields["filter"] = structpb.NewStringValue("foobar")
@@ -691,7 +692,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -699,7 +700,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -715,7 +716,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -723,7 +724,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -793,7 +794,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -817,7 +818,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -841,7 +842,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -943,7 +944,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
Attributes: modifiedAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -6,8 +6,8 @@ import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/managedgroups"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
@@ -46,7 +46,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing oidc attributes",
item: &pb.ManagedGroup{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{}},
},
@@ -55,7 +55,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "bad oidc attributes",
item: &pb.ManagedGroup{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"filter": structpb.NewStringValue("foobar"),
@@ -66,7 +66,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no oidc errors",
item: &pb.ManagedGroup{
Type: auth.OidcSubtype.String(),
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"filter": structpb.NewStringValue(`"/foo/bar" == "zipzap"`),
@@ -101,7 +101,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_1234567890",
Item: &pb.ManagedGroup{
Type: auth.PasswordSubtype.String(),
Type: password.Subtype.String(),
},
},
errContains: fieldError(globals.TypeField, "Cannot modify the resource type."),
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/roles"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -14,6 +13,7 @@ import (
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -8,7 +8,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/roles"
@@ -17,6 +16,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/roles"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -7,7 +7,6 @@ import (
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/errors"
@@ -17,6 +16,7 @@ import (
"github.com/hashicorp/boundary/internal/iam/store"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -9,12 +9,12 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/scopes"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -6,12 +6,12 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/sessions"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -8,7 +8,6 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -19,6 +18,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/sessions"
"github.com/hashicorp/boundary/internal/session"
@@ -12,7 +12,6 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/db/timestamp"
@@ -25,6 +24,7 @@ import (
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -844,7 +844,7 @@ HostSetIterationLoop:
for _, tSet := range hostSets {
hsId := tSet.PublicId
switch host.SubtypeFromId(hsId) {
case host.StaticSubtype:
case static.Subtype:
_, hosts, err := staticHostRepo.LookupSet(ctx, hsId)
if err != nil {
return nil, err
@@ -882,7 +882,7 @@ HostSetIterationLoop:
defaultPort := t.GetDefaultPort()
var endpointHost string
switch host.SubtypeFromId(chosenId.hostId) {
case host.StaticSubtype:
case static.Subtype:
h, err := staticHostRepo.LookupHost(ctx, chosenId.hostId)
if err != nil {
return nil, errors.New(errors.InvalidParameter, op, "errors looking up host")
@@ -1790,7 +1790,7 @@ func validateAuthorizeSessionRequest(req *pbs.AuthorizeSessionRequest) error {
}
if req.GetHostId() != "" {
switch host.SubtypeFromId(req.GetHostId()) {
case host.StaticSubtype:
case static.Subtype:
default:
badFields[globals.HostIdField] = "Incorrectly formatted identifier."
}
@@ -13,9 +13,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/db"
credpb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/credentiallibraries"
@@ -30,6 +28,7 @@ import (
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/servers"
spb "github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/credentiallibraries"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/targets"
@@ -2226,7 +2225,7 @@ func TestAuthorizeSession(t *testing.T) {
Name: clsResp.GetItem().GetName().GetValue(),
Description: clsResp.GetItem().GetDescription().GetValue(),
CredentialStoreId: store.GetPublicId(),
Type: credential.VaultSubtype.String(),
Type: vault.Subtype.String(),
},
}},
// TODO: validate the contents of the authorization token is what is expected
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/errors"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/users"
@@ -15,6 +14,7 @@ import (
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/common/scopeids"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
@@ -9,7 +9,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/db"
@@ -18,6 +17,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/auth"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/servers/controller/handlers/users"
"github.com/hashicorp/boundary/internal/types/scope"