From 5093402d57c6bfbcac88ec96b22c03b2305128ff Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 7 Dec 2023 22:05:09 -0800 Subject: [PATCH 1/2] feat(aws): Implement the account API for aws accounts This change allows clouddriver AWS accounts to use the account management API. Specifically, it allows clouddriver to load AWS accounts from the AccountDefinitionRepository used by the account API. --- ...nAccountDefinitionSourceConfiguration.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AmazonAccountDefinitionSourceConfiguration.java diff --git a/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AmazonAccountDefinitionSourceConfiguration.java b/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AmazonAccountDefinitionSourceConfiguration.java new file mode 100644 index 00000000000..9fc9e2cb39c --- /dev/null +++ b/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AmazonAccountDefinitionSourceConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright 2023 Salesforce, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.netflix.spinnaker.clouddriver.aws.security.config; + +import com.netflix.spinnaker.clouddriver.security.AccountDefinitionRepository; +import com.netflix.spinnaker.clouddriver.security.AccountDefinitionSource; +import com.netflix.spinnaker.credentials.definition.CredentialsDefinitionSource; +import java.util.List; +import java.util.Optional; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +@ConditionalOnProperty({"account.storage.enabled", "account.storage.aws.enabled"}) +public class AmazonAccountDefinitionSourceConfiguration { + @Bean + @Primary + public CredentialsDefinitionSource amazonAccountSource( + AccountDefinitionRepository repository, + Optional>> additionalSources, + AccountsConfiguration accountProperties) { + return new AccountDefinitionSource<>( + repository, + AccountsConfiguration.Account.class, + additionalSources.orElseGet(() -> List.of(accountProperties::getAccounts))); + } +} From 1d665f382f61cf73c0b3ea8cb029d869c476b97d Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Tue, 12 Mar 2024 16:35:15 -0700 Subject: [PATCH 2/2] fix(account): Provide defaults to avoid NPEs An account without requiredGroupMembership or permissions is a valid account. However, certain areas of the code assume that these values are not null and therefore encounter NullPointerExceptions. To avoid this, initialize these fields to a reasonable default value. --- .../aws/security/config/AccountsConfiguration.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AccountsConfiguration.java b/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AccountsConfiguration.java index 9d6c3f111b4..4bb083c3793 100644 --- a/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AccountsConfiguration.java +++ b/clouddriver-aws/src/main/java/com/netflix/spinnaker/clouddriver/aws/security/config/AccountsConfiguration.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.netflix.spinnaker.clouddriver.security.AccessControlledAccountDefinition; import com.netflix.spinnaker.fiat.model.resources.Permissions; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -57,8 +58,8 @@ public static class Account implements AccessControlledAccountDefinition { @Include private Boolean enabled; @Include private List regions; @Include private List defaultSecurityGroups; - private List requiredGroupMembership; - @Include private Permissions.Builder permissions; + private List requiredGroupMembership = new ArrayList<>(); + @Include private Permissions.Builder permissions = new Permissions.Builder(); @Include private String edda; @Include private Boolean eddaEnabled; @Include private Boolean lambdaEnabled;