Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for login MFA resources #1620

Merged
merged 10 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions internal/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
FieldMethod = "method"
FieldNamespace = "namespace"
FieldNamespaceID = "namespace_id"
FieldNamespacePath = "namespace_path"
FieldBackend = "backend"
FieldPathFQ = "path_fq"
FieldData = "data"
Expand Down Expand Up @@ -45,8 +46,8 @@ const (
FieldCurve = "curve"
FieldKeyBits = "key_bits"
FieldForceRWSession = "force_rw_session"
FieldAWSAccessKey = "access_key"
FieldAWSSecretKey = "secret_key"
FieldAccessKey = "access_key"
FieldSecretKey = "secret_key"
FieldEndpoint = "endpoint"
FieldKeyType = "key_type"
FieldKMSKey = "kms_key"
Expand All @@ -62,6 +63,7 @@ const (
FieldAllowReplaceKey = "allow_replace_key"
FieldAllowStoreKey = "allow_store_key"
FieldAnyMount = "any_mount"
FieldID = "id"
FieldUUID = "uuid"
FieldMountAccessor = "mount_accessor"
FieldUsername = "username"
Expand Down Expand Up @@ -124,6 +126,46 @@ const (
FieldResourceGroupName = "resource_group_name"
FieldVMName = "vm_name"
FieldVMSSName = "vmss_name"
FieldUsernameFormat = "username_format"
FieldIntegrationKey = "integration_key"
FieldAPIHostname = "api_hostname"
FieldPushInfo = "push_info"
FieldUsePasscode = "use_passcode"
FieldIssuer = "issuer"
FieldPeriod = "period"
FieldKeySize = "key_size"
FieldQRSize = "qr_size"
FieldAlgorithm = "algorithm"
FieldDigits = "digits"
FieldSkew = "skew"
FieldMaxValidationAttempts = "max_validation_attempts"
FieldOrgName = "org_name"
FieldAPIToken = "api_token"
FieldBaseURL = "base_url"
FieldPrimaryEmail = "primary_email"
FieldSettingsFileBase64 = "settings_file_base64"
FieldUseSignature = "use_signature"
FieldIdpURL = "idp_url"
FieldAdminURL = "admin_url"
FieldAuthenticatorURL = "authenticator_url"
FieldOrgAlias = "org_alias"
FieldType = "type"
FieldMethodID = "method_id"
FieldMFAMethodIDs = "mfa_method_ids"
FieldAuthMethodAccessors = "auth_method_accessors"
FieldAuthMethodTypes = "auth_method_types"
FieldIdentityGroupIDs = "identity_group_ids"
FieldIdentityEntityIDs = "identity_entity_ids"
/*
auth_method_accessors ([]string: []) - Array of auth mount accessor IDs. If present, only auth methods corresponding to the given accessors are checked during login.

auth_method_types ([]string: []) - Array of auth method types. If present, only auth methods corresponding to the given types are checked during login.

identity_group_ids ([]string: []) - Array of identity group IDs. If present, only entities belonging to one of the given groups are checked during login. Note that these IDs can be from the current namespace or a child namespace.

identity_entity_ids ([]string: []) - Array of identity entity IDs. If present, only entities with the given IDs are checked during login. Note that these IDs can be from the current namespace or a child namespace.

*/

/*
common environment variables
Expand Down
57 changes: 57 additions & 0 deletions internal/identity/mfa/duo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package mfa

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-provider-vault/internal/consts"
)

const (
MethodTypeDuo = "duo"
ResourceNameDuo = resourceNamePrefix + MethodTypeDuo
)

var duoSchemaMap = map[string]*schema.Schema{
consts.FieldUsernameFormat: {
Type: schema.TypeString,
Description: "A template string for mapping Identity names to MFA methods.",
Optional: true,
},
consts.FieldSecretKey: {
Type: schema.TypeString,
Required: true,
Description: "Secret key for Duo",
Sensitive: true,
},
consts.FieldIntegrationKey: {
Type: schema.TypeString,
Required: true,
Description: "Integration key for Duo",
Sensitive: true,
},
consts.FieldAPIHostname: {
Type: schema.TypeString,
Required: true,
Description: "API hostname for Duo",
},
consts.FieldPushInfo: {
Type: schema.TypeString,
Optional: true,
Description: "Push information for Duo.",
},
consts.FieldUsePasscode: {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Require passcode upon MFA validation.",
},
}

func GetDuoSchemaResource() (*schema.Resource, error) {
config, _ := NewContextFuncConfig(MethodTypeDuo, PathTypeMethodID, nil, nil, map[string]string{
// API is inconsistent between create/update and read.
"pushinfo": consts.FieldPushInfo,
})

return getMethodSchemaResource(duoSchemaMap, config), nil
}
77 changes: 77 additions & 0 deletions internal/identity/mfa/login_enforcement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package mfa

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-provider-vault/internal/consts"
)

const (
MethodTypeLoginEnforcement = "login-enforcement"
ResourceNameLoginEnforcement = resourceNamePrefix + "login_enforcement"
)

var loginEnforcementSchemaMap = map[string]*schema.Schema{
consts.FieldName: {
Type: schema.TypeString,
Required: true,
Description: "Login enforcement name.",
},
consts.FieldMFAMethodIDs: {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Required: true,
Description: `Set of MFA method UUIDs.`,
},
consts.FieldAuthMethodAccessors: {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: `Set of auth method accessor IDs.`,
},
consts.FieldAuthMethodTypes: {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: `Set of auth method types.`,
},
consts.FieldIdentityGroupIDs: {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: `Set of identity group IDs.`,
},
consts.FieldIdentityEntityIDs: {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: `Set of identity entity IDs.`,
},
}

func GetLoginEnforcementSchemaResource() (*schema.Resource, error) {
config, err := NewContextFuncConfig(MethodTypeLoginEnforcement, PathTypeName, nil, nil, nil)
if err != nil {
return nil, err
}

r := getSchemaResource(loginEnforcementSchemaMap, config, mustAddCommonSchema)
for k, v := range r.Schema {
switch k {
case consts.FieldUUID, consts.FieldName:
v.ForceNew = true
}
}

return r, nil
}
Loading