Slackbot
11/28/2022, 7:15 PMChris Lee
11/28/2022, 7:18 PMVampire
11/28/2022, 7:19 PMChris Lee
11/28/2022, 7:19 PMChris Lee
11/28/2022, 7:21 PMVampire
11/28/2022, 7:33 PMFor security reasons, the configuration cache does not store credentials declared inline.I thought it wouldn't, but I guess that only refers to having hard-coded values inline and it is landing in CC as it is stored in a Gradle property. 😞
Chris Lee
11/28/2022, 7:36 PMVampire
11/28/2022, 7:37 PMChris Lee
11/28/2022, 7:38 PMChris Lee
11/28/2022, 7:38 PMVampire
11/28/2022, 7:39 PMgrossws
11/28/2022, 8:12 PMValueSource
via (this as AuthenticationSupportedInternal).configuredCredentials.set(valueSource)
?Chris Lee
11/28/2022, 8:15 PMChris Lee
11/28/2022, 8:16 PMChris Lee
11/28/2022, 8:17 PMgrossws
11/28/2022, 8:18 PMChris Lee
11/28/2022, 9:22 PMplugins {
`java-library`
`maven-publish`
}
version = "1.0.2"
group = "com.example"
/*
# clearout CC, run build to populate CC
rm -rf .gradle/configuration-cache; ENV_SECRET=ANOTHER-SECRET ./gradlew publish -PfooBar=BAZ_SECRET -PmySecureRepositoryUsername=secret-user -PmySecureRepositoryPassword=secret-password --info --configuration-cache
# dump out all files in CC
find .gradle/configuration-cache
# hexdump the build fingerprint (path will vary)
hexdump -C .gradle/configuration-cache/aqvxhqqm6jsa3zloo4iteoqug/buildfingerprint.bin
For this example, there are five secrets:
1) Environment variable ENV_SECRET (value: ANOTHER-SECRET);
2) Gradle property fooBar (value: BAZ_SECRET);
3) Gradle property mySecretRepositoryUsername (from "safe" credentials) (value: secret-user)
4) Gradle property mySecretRepositoryPassword (from "safe" credentials) (value: secret-password)
5) ValueSource output (value: VALUESOURCE_SECRET)
Each of the above secrets is present, in clear text, in the stored configuration cache.
*/
publishing {
publications {
create<MavenPublication>("library") {
from(components.getByName("java"))
}
}
repositories {
maven {
name = "mySecureRepository"
credentials(PasswordCredentials::class)
url = uri("<https://foo.com>")
}
}
}
val fooTask = tasks.register("foo") {
inputs.property("envVar", providers.environmentVariable("ENV_SECRET"))
inputs.property("gradleProp", providers.gradleProperty("fooBar"))
inputs.property("valueSource", providers.of(MyValueSource::class, {}))
doFirst {
println(inputs.properties["envVar"])
println(inputs.properties["gradleProp"])
println(inputs.properties["valueSource"])
}
}
tasks.named("publish") {
dependsOn(fooTask)
}
abstract class MyValueSource : ValueSource<String,ValueSourceParameters.None> {
override fun obtain(): String? {
// in real code this would be externally-resolved via API call, keystore, etc
return "VALUESOURCE_SECRET"
}
}