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 Vulnerabilities Scan Capability on ECR Repository Creation #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ By default, when the `createRepository` task is executed, the new repository wil
disabled. You can control this behavior using the following setting:

imageTagsMutable in Ecr := false

## Image Scanning
By default, when the `createRepository` task is executed, the new repository will have **Image Scanning**
enabled. You can control this behavior using the following setting:

scanOnPush in Ecr := false

## Cross account publishing

Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ sbtVersion in pluginCrossBuild := {
scalacOptions := Seq("-unchecked", "-feature", "-deprecation", "-encoding", "utf8")

libraryDependencies ++= {
val amazonSdkV = "1.11.672"
val scalaTestV = "3.0.8"
val amazonSdkV = "1.12.186"
val scalaTestV = "3.2.11"
Seq(
"com.amazonaws" % "aws-java-sdk-sts" % amazonSdkV,
"com.amazonaws" % "aws-java-sdk-ecr" % amazonSdkV,
Expand Down
9 changes: 8 additions & 1 deletion src/main/scala/sbtecr/AwsEcr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ private[sbtecr] object AwsEcr extends Aws {
def createRepository(region: Region,
repositoryName: String,
imageTagsMutable: Boolean,
scanOnPush: Boolean,
repositoryPolicyText: Option[String],
repositoryLifecyclePolicyText: Option[String])(implicit logger: Logger): Unit = {

val client = ecr(region)

try {
val result = client.createRepository(new CreateRepositoryRequest().withRepositoryName(repositoryName).withImageTagMutability(if (imageTagsMutable) ImageTagMutability.MUTABLE else ImageTagMutability.IMMUTABLE))
val result = client.createRepository(
new CreateRepositoryRequest()
.withRepositoryName(repositoryName)
.withImageTagMutability(if (imageTagsMutable) ImageTagMutability.MUTABLE else ImageTagMutability.IMMUTABLE)
.withImageScanningConfiguration(new ImageScanningConfiguration().withScanOnPush(scanOnPush))
)
logger.info(s"Repository created in ${region}: arn=${result.getRepository.getRepositoryArn}")
repositoryPolicyText.foreach(setPolicy(client, repositoryName, _))
repositoryLifecyclePolicyText.foreach(putLifecyclePolicy(client, repositoryName, _))
Expand Down
12 changes: 10 additions & 2 deletions src/main/scala/sbtecr/EcrPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object EcrPlugin extends AutoPlugin {
lazy val localDockerImage = settingKey[String]("Local Docker image.")
lazy val repositoryTags = settingKey[Seq[String]]("Tags managed in the Amazon ECR repository.")
lazy val imageTagsMutable = settingKey[Boolean]("Boolean as to whether to make image tags mutable or not")
lazy val scanOnPush = settingKey[Boolean]("Enable vulnerabilities scan on image push")

lazy val fetchDomain = taskKey[String]("Fetch active domain for Amazon ECR access.")
lazy val createRepository = taskKey[Unit]("Create a repository in Amazon ECR.")
Expand All @@ -38,7 +39,8 @@ object EcrPlugin extends AutoPlugin {
repositoryLifecyclePolicyText := None,
localDockerImage := s"${repositoryName.value}:${version.value}",
repositoryDomain := None,
imageTagsMutable := true
imageTagsMutable := true,
scanOnPush := true,
)

lazy val tasks: Seq[Def.Setting[_]] = Seq(
Expand All @@ -55,7 +57,13 @@ object EcrPlugin extends AutoPlugin {
},
createRepository := {
implicit val logger = streams.value.log
AwsEcr.createRepository(region.value, repositoryName.value, imageTagsMutable.value, repositoryPolicyText.value, repositoryLifecyclePolicyText.value)
AwsEcr.createRepository(
region.value, repositoryName.value,
imageTagsMutable.value,
scanOnPush.value,
repositoryPolicyText.value,
repositoryLifecyclePolicyText.value
)
},
login := {
implicit val logger = streams.value.log
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.17.0-SNAPSHOT"
version in ThisBuild := "0.18.0-SNAPSHOT"