Add support for adding LDAP admins based on user/group DNs (#2178)

Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
This commit is contained in:
Lenin Alevski
2022-07-20 18:27:11 -07:00
committed by GitHub
parent c501df927b
commit 251de9fe8a
20 changed files with 1125 additions and 38 deletions

View File

@@ -634,8 +634,8 @@ func getPolicyInfoResponse(session *models.Principal, params policyApi.PolicyInf
return policy, nil
}
// setPolicy() calls MinIO server to assign policy to a group or user.
func setPolicy(ctx context.Context, client MinioAdmin, name, entityName string, entityType models.PolicyEntity) error {
// SetPolicy calls MinIO server to assign policy to a group or user.
func SetPolicy(ctx context.Context, client MinioAdmin, name, entityName string, entityType models.PolicyEntity) error {
isGroup := false
if entityType == models.PolicyEntityGroup {
isGroup = true
@@ -643,7 +643,7 @@ func setPolicy(ctx context.Context, client MinioAdmin, name, entityName string,
return client.setPolicy(ctx, name, entityName, isGroup)
}
// getSetPolicyResponse() performs setPolicy() and serializes it to the handler's output
// getSetPolicyResponse() performs SetPolicy() and serializes it to the handler's output
func getSetPolicyResponse(session *models.Principal, params policyApi.SetPolicyParams) *models.Error {
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()
@@ -656,7 +656,7 @@ func getSetPolicyResponse(session *models.Principal, params policyApi.SetPolicyP
// defining the client to be used
adminClient := AdminClient{Client: mAdmin}
if err := setPolicy(ctx, adminClient, strings.Join(params.Body.Name, ","), *params.Body.EntityName, *params.Body.EntityType); err != nil {
if err := SetPolicy(ctx, adminClient, strings.Join(params.Body.Name, ","), *params.Body.EntityName, *params.Body.EntityType); err != nil {
return ErrorWithContext(ctx, err)
}
return nil

View File

@@ -60,7 +60,7 @@ func (ac adminClientMock) addPolicy(ctx context.Context, name string, policy *ia
return minioAddPolicyMock(name, policy)
}
// mock function setPolicy()
// mock function SetPolicy()
func (ac adminClientMock) setPolicy(ctx context.Context, policyName, entityName string, isGroup bool) error {
return minioSetPolicyMock(policyName, entityName, isGroup)
}
@@ -202,32 +202,32 @@ func TestSetPolicy(t *testing.T) {
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error {
return nil
}
// Test-1 : setPolicy() set policy to user
function := "setPolicy()"
err := setPolicy(ctx, adminClient, policyName, entityName, entityObject)
// Test-1 : SetPolicy() set policy to user
function := "SetPolicy()"
err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject)
if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}
// Test-2 : setPolicy() set policy to group
// Test-2 : SetPolicy() set policy to group
entityObject = models.PolicyEntityGroup
err = setPolicy(ctx, adminClient, policyName, entityName, entityObject)
err = SetPolicy(ctx, adminClient, policyName, entityName, entityObject)
if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}
// Test-3 : setPolicy() set policy to user and get error
// Test-3 : SetPolicy() set policy to user and get error
entityObject = models.PolicyEntityUser
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error {
return errors.New("error")
}
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
funcAssert.Equal("error", err.Error())
}
// Test-4 : setPolicy() set policy to group and get error
// Test-4 : SetPolicy() set policy to group and get error
entityObject = models.PolicyEntityGroup
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error {
return errors.New("error")
}
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
funcAssert.Equal("error", err.Error())
}
}

View File

@@ -116,7 +116,7 @@ func stopProfiling(ctx context.Context, client MinioAdmin) (io.ReadCloser, error
return zippedData, nil
}
// getProfilingStopResponse() performs setPolicy() and serializes it to the handler's output
// getProfilingStopResponse() performs SetPolicy() and serializes it to the handler's output
func getProfilingStopResponse(session *models.Principal, params profileApi.ProfilingStopParams) (io.ReadCloser, *models.Error) {
ctx := params.HTTPRequest.Context()
mAdmin, err := NewMinioAdminClient(session)

View File

@@ -194,7 +194,7 @@ func addUser(ctx context.Context, client MinioAdmin, accessKey, secretKey *strin
// set policies for the newly created user
if len(policies) > 0 {
policyString := strings.Join(policies, ",")
if err := setPolicy(ctx, client, policyString, *accessKey, "user"); err != nil {
if err := SetPolicy(ctx, client, policyString, *accessKey, "user"); err != nil {
return nil, err
}
}

View File

@@ -361,7 +361,7 @@ func TestSetBucketAccess(t *testing.T) {
assert.Equal("error: bucket access not present", err.Error())
}
// Test-5: setBucketAccessPolicy() handle errors on setPolicy call
// Test-5: setBucketAccessPolicy() handle errors on SetPolicy call
minioSetBucketPolicyWithContextMock = func(ctx context.Context, bucketName, policy string) error {
return errors.New("error")
}