Skip to content

Conversation

@paulfantom
Copy link
Contributor

Add a script to provision packet machine and configure it so we can connect to it with libvirt client via SSH or TCP. It also automatically creates temporary ssh key file if needed (default behavior).

/wip

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 21, 2018
@paulfantom
Copy link
Contributor Author

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 21, 2018
@paulfantom paulfantom changed the title add terraform to provision packet machine [WIP] add terraform to provision packet machine Sep 21, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 21, 2018
@paulfantom
Copy link
Contributor Author

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 21, 2018
@paulfantom paulfantom changed the title [WIP] add terraform to provision packet machine add terraform to provision packet machine Sep 27, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 27, 2018
@enxebre
Copy link
Member

enxebre commented Sep 27, 2018

overall looks great to me. Not a blocker at all but we'll probably want parameterise the ip range for the iptable rule

}

resource "packet_ssh_key" "key" {
name = "unlikely_tf_ssh_key_name"
Copy link
Contributor

Choose a reason for hiding this comment

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

You should put ${var.environment_id} here.

@@ -0,0 +1,32 @@
resource "packet_project" "libvirt_actuator" {
name = "libvirt-actuator tests"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put ${var.environment_id} here.

}

resource "packet_device" "libvirt" {
hostname = "${var.environment_id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Prepend something non alpha numeric, in case uuid generates a number fist.


echo 'LIBVIRTD_ARGS="--listen"' >> /etc/sysconfig/libvirtd

iptables -I INPUT -p tcp --dport 16509 -j ACCEPT -m comment --comment "Allow insecure libvirt clients"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the tests going to use TCP or SSH as a transport for libvirt? I don't think it's okay to run these with unauthenticated libvirt listening on the public internet.

Copy link
Member

@enxebre enxebre Sep 27, 2018

Choose a reason for hiding this comment

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

For CI I was thinking on parameterising the ip range allowed to access and then reuse your tls stuff, so we test it as it's consumed by the installer/mao. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that sounds good. I'm not familiar with the e2e tests or the plan for those. Do they use the installer? If so, I think this should be on-hold until openshift/installer#296 merges.

Copy link
Member

Choose a reason for hiding this comment

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

Eventually we might use installer. Currently for mao/aws-actuator we use terraform to create the minimal infra needed to satisfy some actuator assumptions and verify expected behaviour,
See https://github.com/openshift/machine-api-operator/tree/master/tests
e.g The minimal infra for libvirt actuator will contain a network and the ign volumes

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, cool. Then I think it should be pretty easy to use TLS or SSH as the transport from the start. There aren't really any changes required for the actuator. The credentials, certs or SSH keys, just need to be available and the right URI needs to be used. The libvirt library will handle the rest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to add a little more detail on making TLS work: here's a link to the docs

We just need to generate the TLS assets somehow -- could use certtool, cfssl, or even Terraform if we don't want to use the Go tool in the installer PR. Then configure libvirtd to point to the certs and use a URI like: qemu+tls://$IP/system?pkipath=/path/to/certs

That should be enough and pretty secure as long as no one can access the generated certs and they are one-time use.

Copy link
Contributor Author

@paulfantom paulfantom Sep 27, 2018

Choose a reason for hiding this comment

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

It would be probably easier to adapt it to use SSH as this already need SSH keys to connect to instance. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally fine. As long as we're doing authentication and encryption somehow.

@@ -0,0 +1,32 @@
resource "packet_project" "libvirt_actuator" {
Copy link
Contributor

@bison bison Sep 27, 2018

Choose a reason for hiding this comment

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

Does this create a project for every build? We probably want a single re-used project. That will let us manage permissions for it.

@spangenberg
Copy link
Contributor

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2018
@paulfantom
Copy link
Contributor Author

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 28, 2018
set +e

# Your Packet user account
if [ "$PACKET_AUTH_TOKEN" == "" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

-z vis-a-vis == ""?

@spangenberg
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 28, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: paulfantom, spangenberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [paulfantom,spangenberg]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 83c10e8 into master Sep 28, 2018
ssh_path="/tmp/packet_id_rsa.pub"
fi
terraform init -input=false
terraform plan -input=false -out=tfplan.out && terraform apply -input=false -auto-approve tfplan.out
Copy link
Contributor

Choose a reason for hiding this comment

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

As we have -e this could be two separate commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I will fix that in a follow-up PR

;;
"destroy")
terraform destroy -input=false -auto-approve
rm /tmp/packet_id_rsa* || :
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use rm -f, instead of ||?

#/bin/bash

yum install -y -d1 libvirt libvirt-daemon-kvm
usermod -aG libvirt root
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I've looked to see how this script is used (or when) but do you not need newgrp libvirt here having modified the groups?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used to install libvirt on packet host the easiest way.


iptables -I INPUT -p tcp --dport 16509 -j ACCEPT -m comment --comment "Allow insecure libvirt clients"

systemctl start libvirtd
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 also need systemctl enable libvirtd? Is there any expectation of this starting on reboot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, those machines aren't expected to be rebooted.

@paulfantom paulfantom deleted the packet branch September 28, 2018 14:38
openshift-merge-robot added a commit that referenced this pull request Oct 1, 2018
Incorporate suggestions from #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants