Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Install assets only via Ignition#3183

Merged
squat merged 2 commits intocoreos:masterfrom
squeed:no-assets
Apr 23, 2018
Merged

Install assets only via Ignition#3183
squat merged 2 commits intocoreos:masterfrom
squeed:no-assets

Conversation

@squeed
Copy link

@squeed squeed commented Apr 16, 2018

This PR does the following:

  • No longer zips up /generated and uploads it to S3
  • Installs all needed files via Ignition
  • Stops writing some files to /generated
  • Cleans up the ignition "API"

@coreosbot
Copy link

Can one of the admins verify this patch?

@abhinavdahiya
Copy link
Contributor

abhinavdahiya commented Apr 16, 2018

@squeed

  1. in old method only the bootstrap node pulled the secrets and tried to bootstrap using bootkube. Is this PR changing that behavior, i see init-assets.sh is dropped which enforced that behaviour.
  2. also rm-assets.sh would remove all these secrets from disk after bootstrapping. that also seems to be dropped.
  3. sensitive data will be served through config/master endpoint in s3 bucket which is public.

@squeed
Copy link
Author

squeed commented Apr 16, 2018

@abhinavdahiya
In the old method, we uploaded both the master ignition file without secrets and a zip file containing secrets to S3. All this PR does is move everything that was in that zip file in to ignition. This was originally done because of size limitations on ignition files. It doesn't otherwise change the bootstrap process.

You are right that the .zip file has a different ACL. I'll change that.

The downloaded secret files are never deleted from the master - perhaps they should be, but that's not anything different in this PR. All "rm-assets.sh" does (and did) is overwrite the uploaded S3 files with empty files.

@squeed squeed force-pushed the no-assets branch 2 times, most recently from 8064d4c to 0b34564 Compare April 17, 2018 14:01
@squeed
Copy link
Author

squeed commented Apr 17, 2018

@abhinavdahiya Changed the ignition flow to redirect to a s3:// url. Ignition can fetch private s3:// urls.

@enxebre
Copy link
Contributor

enxebre commented Apr 17, 2018

ok to test

REGION=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone | sed '"'"'s/[a-zA-Z]$//'"'"')
/usr/bin/aws --region="$REGION" s3 cp /tmp/assets.zip s3://"$LOCATION/assets.zip"
/usr/bin/aws --region="$REGION" s3 cp /tmp/assets.zip s3://"$LOCATION/config/master"
/usr/bin/aws --region="$REGION" s3 cp /tmp/empty s3://"$LOCATION/config/bootstrap"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have 'config/bootstrap' ?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. it's the third step in the redirect chain, and it has a private acl.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should also include a set -u here, so if $LOCATION is omitted bash will complain, and we don't just get a cryptic S3 API error back.

# folder, we write it in the Terraform managed hidden folder `.terraform`.
output_path = "./.terraform/generated_${sha1("${var.tectonic_cluster_id}")}.zip"
# The public ignition configuration
data "ignition_config" "bootstrap_redirect" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I’ve been scratching my head to figure out how to make the http s3 endpoint more secure, this is just very nice and super simple, thanks!

@squeed
Copy link
Author

squeed commented Apr 17, 2018

The tests have failed because it's looking for files in /generated that don't exist anymore.

@squeed
Copy link
Author

squeed commented Apr 17, 2018

I'm stuck now. All of the tests expect to be able to compare /generated/manifests and /generated/tectonic with the state of the cluster. We don't write those any more (and there's no need to). Do we need to render those to disk just so tests can run?

@enxebre
Copy link
Contributor

enxebre commented Apr 18, 2018

The test failing is checking that some expected files are written to local disk, as this was part of the bootstrap workflow runtime https://github.com/coreos/tectonic-installer/blob/master/tests/rspec/lib/shared_examples/k8s.rb#L65
https://github.com/coreos/tectonic-installer/blob/master/tests/rspec/lib/operators.rb
Since this won't be part of the workflow anymore we don't need to test it so we can remove it.
Instead with could leverage ssh_exec to test those manifests are generated in the right path inside the machine (this would require the tests to differentiate the bootstrap node ip from the other nodes ips)
@cpanato wdyt?
Also if we eventually move this out of tf, we can also unit test the generated ignition file to match an expected config

@squeed
Copy link
Author

squeed commented Apr 18, 2018

The easiest answer is probably to enable a test mode that renders some files to disk.

@squeed
Copy link
Author

squeed commented Apr 18, 2018

all green!

enxebre
enxebre previously approved these changes Apr 18, 2018
spangenberg
spangenberg previously approved these changes Apr 18, 2018
Copy link
Contributor

@colhom colhom left a comment

Choose a reason for hiding this comment

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

Great stuff, this really cleans up the provisioning process.

In general, also wondering why the directory structure needed to shuffle around (perhaps I'm missing something.) Would be nice if the generated/ folder had same structure as before, if you think it's possible.


output "ignition_file_id_list" {
value = [
"${data.ignition_file.manifest_file_list.*.id}",
Copy link
Contributor

Choose a reason for hiding this comment

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

This splat evaluates to a list, which means the ignition_file_id_list will be a list which contains a list element (which I'm assuming is not intended). A pretty robust way to deal with this is and ensure the output is always a flat list of id's:

value = [  "${flatten(list(data.foo.bar.*.id, data.blah.thing.id, data.blah.otherthing.id))}"  ]

Copy link
Author

Choose a reason for hiding this comment

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

oh man, thanks!

"${data.ignition_file.root_ca_cert_pem.id}",
"${data.ignition_file.ingress_ca_cert_pem.id}",
"${data.ignition_file.etcd_ca_cert_pem.id}",
"${data.ignition_file.custom_ca_cert_pem.*.id}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here, when mixing splat id lists and singelton ids into a single list, use flatten(list(...)) so you get a flat list consistently


output "ignition_file_id_list" {
value = [
"${data.ignition_file.tectonic_manifest_list.*.id}",
Copy link
Contributor

Choose a reason for hiding this comment

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

flatten(list(...)))

path = "/opt/tectonic/tls/root-ca.crt"

content {
content = "${var.root_ca_cert_pem == "" ? join("", tls_self_signed_cert.root_ca.*.cert_pem) : var.root_ca_cert_pem}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ternary expressions conditionally consuming lists can make terraform behave "oddly". Would recommend doing something more generic like:

${join("\n",compact(flatten(list(tls_self_signed_cert.root_ca.*.cert_pem, var.root_ca_cert_pem))))}

Also- I'd think you'd want to join the certificate pem blocks using a newline, instead of empty string?

Copy link
Author

Choose a reason for hiding this comment

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

I just copied this from the line above; while you're probably right, I'd rather not change what "works". I'm not sure that custom certificates work right now anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

a good rule of thumb w/ terraform is to only use ternary expressions when all inputs and outputs are primitives. we learned this the hard way in earlier versions of terraform, for all I know this could be perfectly fine with more current versions.


data "ignition_file" "aggregator_ca_key" {
filesystem = "root"
mode = "0644"
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and all other private keys) need to be 0600 mode

}

data "ignition_config" "bootstrap" {
files = ["${compact(list(
Copy link
Contributor

Choose a reason for hiding this comment

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

This will also be a nested list situation, recommend flattening the whole list. (nice use of compact here).

"${module.etcd_certs.ignition_file_id_list}",
]

systemd = ["${compact(list(
Copy link
Contributor

Choose a reason for hiding this comment

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

flatten here as well

# some files we want rendered to disk for other use
resource "local_file" "kubeconfig-kubelet" {
content = "${module.bootkube.kubeconfig-kubelet_rendered}"
filename = "./generated/auth/kubeconfig-kubelet"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if these generated file paths were canonically defined in a locals block.

REGION=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone | sed '"'"'s/[a-zA-Z]$//'"'"')
/usr/bin/aws --region="$REGION" s3 cp /tmp/assets.zip s3://"$LOCATION/assets.zip"
/usr/bin/aws --region="$REGION" s3 cp /tmp/assets.zip s3://"$LOCATION/config/master"
/usr/bin/aws --region="$REGION" s3 cp /tmp/empty s3://"$LOCATION/config/bootstrap"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also include a set -u here, so if $LOCATION is omitted bash will complain, and we don't just get a cryptic S3 API error back.

output_path = "./.terraform/generated_${sha1("${var.tectonic_cluster_id}")}.zip"
# The public ignition configuration
data "ignition_config" "bootstrap_redirect" {
replace {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason this a replace and not an append block?

Copy link
Author

Choose a reason for hiding this comment

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

Basically to keep people honest :-).

Copy link
Author

Choose a reason for hiding this comment

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

In other words, I don't want there any to be any chance that there's insecure ignition information out there.

@squeed squeed dismissed stale reviews from spangenberg and enxebre via 2a26fc7 April 20, 2018 14:48
This PR does the following:
- No longer zips up /generated and uploads it to S3
- Installs all needed files via Ignition
- Stops writing some files to /generated
- Cleans up the ignition API
@squeed
Copy link
Author

squeed commented Apr 20, 2018

@colhom thanks a ton for the terraform tips! I reverted the directory structure change, there was no real reason for it.

Copy link
Contributor

@colhom colhom left a comment

Choose a reason for hiding this comment

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

LGTM!

@squat squat merged commit f0c524c into coreos:master Apr 23, 2018
@squat
Copy link
Contributor

squat commented Apr 23, 2018

🎉

@enxebre enxebre mentioned this pull request Apr 23, 2018
@squeed squeed mentioned this pull request Apr 23, 2018
wking added a commit to wking/openshift-installer that referenced this pull request Aug 17, 2018
The last consumer was removed in b2e0bcf (Don't upload /generated to
S3 - only use Ignition, 2018-04-13, coreos/tectonic-installer#3183).
wking added a commit to wking/openshift-installer that referenced this pull request Nov 18, 2018
This variable was added in a2232f3 (platform/aws: create bootstrap
step, 2018-02-14, coreos/tectonic-installer#2946), to force VPC
creation after the S3 bucket.  But that dependency was removed in
b2e0bcf (Don't upload /generated to S3 - only use Ignition,
2018-04-13, coreos/tectonic-installer#3183), so we no longer need the
variable.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants