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

Initial merge of Development to Master #1

Merged
merged 71 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
c8964c8
Rename project
mccloman Aug 5, 2020
5d1fde2
adding modified docker files for testing
mccloman Aug 6, 2020
4b4bed4
clean up
mccloman Aug 6, 2020
4cbb54e
Clean up imports
mccloman Aug 10, 2020
80157d9
Clean up gralde files
mccloman Aug 10, 2020
64a2fdb
Remove unused class
mccloman Aug 10, 2020
bd87af0
clean up gradle file
mccloman Aug 10, 2020
b5fc21c
Add null checking
mccloman Aug 10, 2020
4a9aa90
Make url and sync frequency configurable
mccloman Aug 10, 2020
383f34e
Separate agent schedulers
mccloman Aug 10, 2020
ff1d909
Remove unnecessary imports
mccloman Aug 10, 2020
4ce1301
fix default url
mccloman Aug 10, 2020
751208c
Clean up sync()
mccloman Aug 10, 2020
591e398
Update comment
mccloman Aug 10, 2020
cc27093
change switch statement to ifs
mccloman Aug 10, 2020
639d764
Position literals first in String comparisons
mccloman Aug 10, 2020
9bf3e9a
reformat code
mccloman Aug 10, 2020
045dd3a
update copyright
mccloman Aug 10, 2020
17a5d72
remove unnecessary files
mccloman Aug 10, 2020
2a57ea9
Add README
mccloman Aug 10, 2020
a7b526c
Rename project
mccloman Aug 5, 2020
25528d3
adding modified docker files for testing
mccloman Aug 6, 2020
18956a4
clean up
mccloman Aug 6, 2020
7626367
Clean up imports
mccloman Aug 10, 2020
f2d6473
Clean up gralde files
mccloman Aug 10, 2020
9ee096e
Remove unused class
mccloman Aug 10, 2020
814fe13
clean up gradle file
mccloman Aug 10, 2020
eb4e479
Add null checking
mccloman Aug 10, 2020
e3d2bee
Make url and sync frequency configurable
mccloman Aug 10, 2020
bcf1fe9
Separate agent schedulers
mccloman Aug 10, 2020
d6d8993
Remove unnecessary imports
mccloman Aug 10, 2020
3bcecb6
fix default url
mccloman Aug 10, 2020
83bc90a
Clean up sync()
mccloman Aug 10, 2020
19b0f70
Update comment
mccloman Aug 10, 2020
dccb392
change switch statement to ifs
mccloman Aug 10, 2020
2bd42fc
Position literals first in String comparisons
mccloman Aug 10, 2020
718489f
reformat code
mccloman Aug 10, 2020
c5d0295
update copyright
mccloman Aug 10, 2020
8009b60
remove unnecessary files
mccloman Aug 10, 2020
91f6a9e
Add README
mccloman Aug 10, 2020
bd886c8
Merge branch 'development' of github.com:awslabs/aws-account-registra…
mccloman Aug 10, 2020
be4cadd
Add more information on how to use this plugin
mccloman Aug 11, 2020
5e87376
Indicate what fields are required
mccloman Aug 11, 2020
ff31a73
Remove unused function
mccloman Aug 11, 2020
1079c07
Slightly cleaner account checking
mccloman Aug 11, 2020
40f3877
url formating change
nabuskey Aug 11, 2020
032ade5
reformat setting account fields
mccloman Aug 11, 2020
e3f4d04
Throw exception when rest client fails to GET
mccloman Aug 11, 2020
99e23b5
Pull account conversion out of AmazonPollingSynchronizer
mccloman Aug 11, 2020
fce9186
Prvent calling sync() on getone() everytime
mccloman Aug 11, 2020
0bb2c4a
Update JSON schema
mccloman Aug 11, 2020
1f0e135
Add account constructor
mccloman Aug 11, 2020
39c557a
Use hashmaps instead of lists when constructing credentials
mccloman Aug 11, 2020
a47e8e9
Support for enabling / disabling accounts
mccloman Aug 11, 2020
6dbab5b
Fix providers not being enabled when multiple providers specified
mccloman Aug 11, 2020
bc47048
Add tests for Response
mccloman Aug 11, 2020
9dc5fb9
Update gradle to enable tests
mccloman Aug 11, 2020
1745688
Correct property name
mccloman Aug 12, 2020
158e0ea
Remove AccountRegistrationProperties to remove hardcoded default values
mccloman Aug 12, 2020
f637690
Fix README
mccloman Aug 12, 2020
c742a8b
Cleanup Response.java
nabuskey Aug 12, 2020
12811d5
Add pagination support in JSON deserialization
mccloman Aug 12, 2020
c510aac
Add support for suspended accounts and role names without role/ prefix
mccloman Aug 12, 2020
263f149
Update provider list handling
mccloman Aug 12, 2020
bcb604b
Make agent schedulers private
mccloman Aug 12, 2020
c117989
Update README to include known issues
mccloman Aug 12, 2020
f35d964
Add default constructor to Account
mccloman Aug 13, 2020
13c607b
refactor account response
nabuskey Aug 14, 2020
78b5c5d
Feature/sig4 auth (#3)
nabuskey Aug 18, 2020
541f27d
finalized account schema (#5)
nabuskey Aug 21, 2020
4ce653f
Bugfix: response validity check (#7)
nabuskey Aug 24, 2020
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
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
build
.gradle
.idea

*.class
out/
.gradle/
build/
*.iml
*.ipr
*.iws
TestScript.groovy
.idea/
.classpath
.project
.settings/
bin/
application.yml
*.hprof
README.html
*~
es-tmp/
clouddriver-oracle-bmcs/bmcs-sdk
gatling.conf
.DS_Store
/plugins/

39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
## My Project

TODO: Fill this README out!

Be sure to:

* Change the title in this README
* Edit your repository description on GitHub
## Spinnaker Plugin for Dynamic Account Registration
nabuskey marked this conversation as resolved.
Show resolved Hide resolved

### Usage
1. Run `./gradlew releaseBundle` in the root of this project.
2. The above command will create a zip file, `build/distributions/spinnaker-aws-account-registration*.zip`.
3. Copy the zip file to Clouddriver plugin directory. Defaults to `/opt/clouddriver/plugins`. This directory can be
specified by the `plugins-root-path` configuration property.
4. Enable the plugin by placing the following in [Clouddriver profile](https://spinnaker.io/reference/halyard/custom/#custom-profiles)


```yaml
spinnaker:
extensibility:
plugins-root-path: /opt/clouddriver/plugins
plugins:
AWS.AccountRegistration:
enabled: true
repositories: {}
strict-plugin-loading: false
```

### Available configuration properties:
```yaml
accountProvision:
url: 'http://localhost:8080/hello' # Remote host address.
pullFrequencyInMilliSeconds: 10000 # How often this plugin should query the remote host.
syncAgentFrequencyInMilliSeconds: 10000 # How often agent scheduler should run.
```

### Known issues
1. When creating lambda functions, on-demand cache update may fail. This seems to be a bug in caching agent in `clouddriver-lambda`.

## Security

Expand Down
78 changes: 78 additions & 0 deletions account-registration/account-registration.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
buildscript {
ext.kotlin_version = '1.3.50'

repositories {
mavenCentral()
}
dependencies {
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "io.spinnaker.plugin.service-extension"
//apply plugin: "maven-publish"
apply plugin: 'groovy'
apply plugin: 'java'
//apply plugin: 'kotlin-kapt'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
maven { url "http://dl.bintray.com/spinnaker/spinnaker/" }
}

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs += ["src/main/java"]

spinnakerPlugin {
serviceName = "clouddriver"
pluginClass = "com.amazon.aws.spinnaker.plugin.registration.AccountRegistrationPlugin"
requires = "clouddriver>=5.0.0"
}


dependencies {
// compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// api "org.codehaus.groovy:groovy"
compileOnly "org.codehaus.groovy:groovy-all:+"
compileOnly (group: 'org.springframework', name: 'spring-context', version: '5.2.1.RELEASE')
compileOnly (group: 'com.netflix.spinnaker.kork', name: 'kork-plugins-spring-api', version: "${korkVersion}")
compileOnly (group: 'org.springframework', name: 'spring-web', version: '5.2.2.RELEASE')
compileOnly (group: 'com.netflix.spinnaker.orca', name: 'orca-core', version: "${orcaVersion}")
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-api:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-aws:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-ecs:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:cats-core:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-security:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-eureka:5.67.0'
compileOnly 'com.netflix.spinnaker.clouddriver:clouddriver-core:5.67.0'
compileOnly 'com.netflix.spinnaker.fiat:fiat-core:1.22.0'
compileOnly 'com.amazonaws:aws-java-sdk:1.11.802'
compileOnly 'org.projectlombok:lombok:+'
annotationProcessor "org.projectlombok:lombok:+"
annotationProcessor("org.pf4j:pf4j:$pf4jVersion")

testImplementation (group: 'com.netflix.spinnaker.orca', name: 'orca-core', version: "${orcaVersion}")
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-api:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-aws:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-ecs:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:cats-core:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-security:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-eureka:5.67.0'
testImplementation 'com.netflix.spinnaker.clouddriver:clouddriver-core:5.67.0'
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.2"
testImplementation group: 'io.strikt', name: 'strikt-core', version: '0.22.1'
testImplementation group: 'dev.minutest', name: 'minutest', version: '1.10.0'

testRuntime "org.junit.jupiter:junit-jupiter-engine:5.3.2"
testRuntime "org.junit.platform:junit-platform-launcher:1.3.2"
}

test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.amazon.aws.spinnaker.plugin.registration;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.netflix.spinnaker.fiat.model.resources.Permissions;
import lombok.Data;

import java.util.List;

@Data
public class Account {
@JsonProperty("AccountName")
private String name; // required. MUST be unique.
@JsonProperty("AccountId")
private String accountId; // required.
@JsonProperty("SpinnakerAssumeRole")
private String assumeRole; // required.
@JsonProperty("Regions")
private List<String> regions; // required.
@JsonProperty("SpinnakerProviders")
private List<String> providers; // required.
@JsonProperty("SpinnakerEnabled")
private Boolean enabled = false; // required.
// Optional
@JsonProperty("DeletedAt")
private Long deletedAt;
@JsonProperty("Permissions")
private Permissions.Builder permissions;
@JsonProperty("Environment")
private String environment;
@JsonProperty("AccountArn")
private String accountArn;
@JsonProperty("AccountEmail")
private String accountEmail;
@JsonProperty("Profile")
private String profile;
@JsonProperty("ServiceId")
private String serviceId;
@JsonProperty("Status")
private String status;
@JsonProperty("CreatedAt")
private String createdAt;
@JsonProperty("UpdatedAt")
private String updatedAt;
// Pagination
@JsonProperty("Pagination")
private AccountPagination pagination;

Account(String name, String accountId, String assumeRole, List<String> regions,
List<String> providers, Boolean enabled) {
this.name = name;
this.accountId = accountId;
this.assumeRole = assumeRole;
this.regions = regions;
this.providers = providers;
this.enabled = enabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.amazon.aws.spinnaker.plugin.registration;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class AccountPagination {
@JsonProperty("Limit")
private String limit;
@JsonProperty("NextUrl")
private String nextUrl;
@JsonProperty("CursorState")
private String cursorState;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.amazon.aws.spinnaker.plugin.registration;

import com.netflix.spinnaker.kork.plugins.api.spring.PrivilegedSpringPlugin;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.PluginWrapper;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class AccountRegistrationPlugin extends PrivilegedSpringPlugin {

public AccountRegistrationPlugin(PluginWrapper wrapper) {
super(wrapper);
}

@Override
public void registerBeanDefinitions(BeanDefinitionRegistry registry) {
BeanDefinition lazyLoadCredentialsRepositoryDefinition = primaryBeanDefinitionFor(LazyLoadCredentialsRepository.class);
try {
log.debug("Registering bean: {}", lazyLoadCredentialsRepositoryDefinition.getBeanClassName());
registry.registerBeanDefinition("accountCredentialsRepository", lazyLoadCredentialsRepositoryDefinition);
} catch (BeanDefinitionStoreException e) {
log.error("Could not register bean {}", lazyLoadCredentialsRepositoryDefinition.getBeanClassName());
}
List<Class> classes = new ArrayList<>(Arrays.asList(AmazonPollingSynchronizer.class,
AmazonEC2InfraCachingAgentScheduler.class,
AmazonAWSCachingAgentScheduler.class, AmazonECSCachingAgentScheduler.class));
for (Class calssToAdd : classes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calssToAdd typo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. It's fixed in feature/refactor-account-response. Thanks!

BeanDefinition beanDefinition = beanDefinitionFor(calssToAdd);
try {
log.debug("Registering bean: {}", beanDefinition.getBeanClassName());
registerBean(beanDefinition, registry);
} catch (ClassNotFoundException e) {
log.error("Could not register bean {}", beanDefinition.getBeanClassName());
}
}
}

@Override
public void start() {
log.info("{} plugin started", this.getClass().getSimpleName());
}

@Override
public void stop() {
log.info("{} plugin stopped", this.getClass().getSimpleName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.amazon.aws.spinnaker.plugin.registration;

import com.netflix.spinnaker.clouddriver.aws.security.config.CredentialsConfig;
import com.netflix.spinnaker.clouddriver.ecs.security.ECSCredentialsConfig;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Data
public class AccountsStatus {
public HashMap<String, CredentialsConfig.Account> ec2Accounts;
public HashMap<String, ECSCredentialsConfig.Account> ecsAccounts;
public List<String> deletedAccounts;

public List<CredentialsConfig.Account> getEC2AccountsAsList() {
List<CredentialsConfig.Account> desiredEc2Accounts = new ArrayList<>();
desiredEc2Accounts.addAll(ec2Accounts.values());
return desiredEc2Accounts;
}

public List<ECSCredentialsConfig.Account> getECSAccountsAsList() {
List<ECSCredentialsConfig.Account> desiredEcsAccounts = new ArrayList<>();
desiredEcsAccounts.addAll(ecsAccounts.values());
return desiredEcsAccounts;
}
}
Loading