Skip to content

Commit 9b3aed6

Browse files
Pin Alpine image digest and add SHA256 verification for TF provider download
Co-authored-by: Isaac
1 parent adfdee6 commit 9b3aed6

8 files changed

Lines changed: 52 additions & 11 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.22 as builder
1+
FROM alpine:3.22@sha256:55ae5d250caebc548793f321534bc6a8ef1d116f334f18f4ada1b2daad3251b2 as builder
22

33
RUN ["apk", "add", "jq"]
44
RUN ["apk", "add", "bash"]
@@ -13,7 +13,7 @@ ARG ARCH
1313
RUN /build/docker/setup.sh
1414

1515
# Start from a fresh base image, to remove any build artifacts and scripts.
16-
FROM alpine:3.22
16+
FROM alpine:3.22@sha256:55ae5d250caebc548793f321534bc6a8ef1d116f334f18f4ada1b2daad3251b2
1717

1818
ENV DATABRICKS_TF_EXEC_PATH "/app/bin/terraform"
1919
ENV DATABRICKS_TF_CLI_CONFIG_FILE "/app/config/config.tfrc"

bundle/deploy/terraform/pkg.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ type Checksum struct {
7777
}
7878

7979
type TerraformMetadata struct {
80-
Version string `json:"version"`
81-
Checksum Checksum `json:"checksum"`
82-
ProviderHost string `json:"providerHost"`
83-
ProviderSource string `json:"providerSource"`
84-
ProviderVersion string `json:"providerVersion"`
80+
Version string `json:"version"`
81+
Checksum Checksum `json:"checksum"`
82+
ProviderHost string `json:"providerHost"`
83+
ProviderSource string `json:"providerSource"`
84+
ProviderVersion string `json:"providerVersion"`
85+
ProviderChecksum Checksum `json:"providerChecksum"`
8586
}
8687

8788
func NewTerraformMetadata(ctx context.Context) (*TerraformMetadata, error) {
@@ -98,6 +99,10 @@ func NewTerraformMetadata(ctx context.Context) (*TerraformMetadata, error) {
9899
ProviderHost: schema.ProviderHost,
99100
ProviderSource: schema.ProviderSource,
100101
ProviderVersion: schema.ProviderVersion,
102+
ProviderChecksum: Checksum{
103+
LinuxAmd64: schema.ProviderChecksumLinuxAmd64,
104+
LinuxArm64: schema.ProviderChecksumLinuxArm64,
105+
},
101106
}, nil
102107
}
103108

bundle/deploy/terraform/pkg_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ func TestTerraformArchiveChecksums(t *testing.T) {
5454
downloadAndChecksum(t, armUrl, tv.ChecksumLinuxArm64)
5555
}
5656

57+
func TestTerraformProviderArchiveChecksums(t *testing.T) {
58+
metadata, err := NewTerraformMetadata(t.Context())
59+
require.NoError(t, err)
60+
61+
amdUrl := fmt.Sprintf("https://github.com/databricks/terraform-provider-databricks/releases/download/v%s/terraform-provider-databricks_%s_linux_amd64.zip", metadata.ProviderVersion, metadata.ProviderVersion)
62+
armUrl := fmt.Sprintf("https://github.com/databricks/terraform-provider-databricks/releases/download/v%s/terraform-provider-databricks_%s_linux_arm64.zip", metadata.ProviderVersion, metadata.ProviderVersion)
63+
64+
downloadAndChecksum(t, amdUrl, metadata.ProviderChecksum.LinuxAmd64)
65+
downloadAndChecksum(t, armUrl, metadata.ProviderChecksum.LinuxArm64)
66+
}
67+
5768
func TestGetTerraformVersionDefault(t *testing.T) {
5869
// Verify that the default version is used
5970
tv, isDefault, err := GetTerraformVersion(t.Context())

bundle/internal/tf/codegen/generator/generator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ func (c *collection) Generate(path string) error {
3535
}
3636

3737
type root struct {
38-
OutputFile string
39-
ProviderVersion string
38+
OutputFile string
39+
ProviderVersion string
40+
ProviderChecksumLinuxAmd64 string
41+
ProviderChecksumLinuxArm64 string
4042
}
4143

4244
func (r *root) Generate(path string) error {
@@ -147,8 +149,10 @@ func Run(ctx context.Context, schema *tfjson.ProviderSchema, path string) error
147149
// Generate root.go
148150
{
149151
r := &root{
150-
OutputFile: "root.go",
151-
ProviderVersion: schemapkg.ProviderVersion,
152+
OutputFile: "root.go",
153+
ProviderVersion: schemapkg.ProviderVersion,
154+
ProviderChecksumLinuxAmd64: schemapkg.ProviderChecksumLinuxAmd64,
155+
ProviderChecksumLinuxArm64: schemapkg.ProviderChecksumLinuxArm64,
152156
}
153157
err := r.Generate(path)
154158
if err != nil {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
package schema
22

33
const ProviderVersion = "1.111.0"
4+
5+
// Checksums for the Databricks Terraform provider archive. These are not used
6+
// inside the CLI. They are co-located here to be output in the
7+
// "databricks bundle debug terraform" output. Downstream applications like the
8+
// CLI docker image use these checksums to verify the integrity of the downloaded
9+
// provider archive. Please update these when the provider version is bumped.
10+
// The checksums are obtained from https://github.com/databricks/terraform-provider-databricks/releases.
11+
const ProviderChecksumLinuxAmd64 = "c1b46bbaf5c4a0b253309dad072e05025e24731536719d4408bacd48dc0ccfd9"
12+
const ProviderChecksumLinuxArm64 = "ce379c424009b01ec4762dee4d0db27cfc554d921b55a0af8e4203b3652259e9"

bundle/internal/tf/codegen/templates/root.go.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Root struct {
2222
const ProviderHost = "registry.terraform.io"
2323
const ProviderSource = "databricks/databricks"
2424
const ProviderVersion = "{{ .ProviderVersion }}"
25+
const ProviderChecksumLinuxAmd64 = "{{ .ProviderChecksumLinuxAmd64 }}"
26+
const ProviderChecksumLinuxArm64 = "{{ .ProviderChecksumLinuxArm64 }}"
2527

2628
func NewRoot() *Root {
2729
return &Root{

bundle/internal/tf/schema/root.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/setup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ mv zip/terraform/terraform /app/bin/terraform
3030
TF_PROVIDER_NAME=terraform-provider-databricks_${DATABRICKS_TF_PROVIDER_VERSION}_linux_${ARCH}.zip
3131
mkdir -p /app/providers/registry.terraform.io/databricks/databricks
3232
wget https://github.com/databricks/terraform-provider-databricks/releases/download/v${DATABRICKS_TF_PROVIDER_VERSION}/${TF_PROVIDER_NAME} -O /app/providers/registry.terraform.io/databricks/databricks/${TF_PROVIDER_NAME}
33+
34+
# Verify the provider checksum.
35+
EXPECTED_PROVIDER_CHECKSUM="$(/app/databricks bundle debug terraform --output json | jq -r .terraform.providerChecksum.linux_$ARCH)"
36+
COMPUTED_PROVIDER_CHECKSUM=$(sha256sum /app/providers/registry.terraform.io/databricks/databricks/${TF_PROVIDER_NAME} | awk '{ print $1 }')
37+
if [ "$COMPUTED_PROVIDER_CHECKSUM" != "$EXPECTED_PROVIDER_CHECKSUM" ]; then
38+
echo "Checksum mismatch for Terraform provider. Version: $DATABRICKS_TF_PROVIDER_VERSION, Arch: $ARCH, Expected checksum: $EXPECTED_PROVIDER_CHECKSUM, Computed checksum: $COMPUTED_PROVIDER_CHECKSUM."
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)