Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
.idea

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Terraform plan file
*.tfplan.*
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ test: # Run unit test
integration: deps-cgo ## Run integration test
go test -v sigs.k8s.io/cluster-api-provider-libvirt/test/integration

.PHONY: e2e
e2e: deps-cgo ## Run end-to-end test
hack/packet-provision.sh install
#TODO run tests
hack/packet-provision.sh destroy

.PHONY: lint
lint: ## Go lint your code
hack/go-lint.sh $(go list -f '{{ .ImportPath }}' ./...)
Expand Down
36 changes: 36 additions & 0 deletions hack/packet-provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set +e

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

Copy link
Copy Markdown
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 == ""?

echo "You need to set PACKET_AUTH_TOKEN variable first."
echo "Make sure that your SSH key is also set in packet.net"
exit 1
fi

export TF_VAR_environment_id=${ENVIRONMENT_ID:-$(uuidgen | cut -c1-8)}

cd ./prebuild
case ${1} in
"install")
ssh_path="$TF_VAR_ssh_key_path"
if [ "$TF_VAR_ssh_key_path" == "" ]; then
echo -e "\e[33mCreating temporary SSH file\e[0m"
ssh-keygen -t rsa -b 4096 -C "temporary packet.net key" -P "" -f "/tmp/packet_id_rsa" -q
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
Copy Markdown
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
Copy Markdown
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

echo -e "\e[32m"
echo -e "*** Your packet.net host is called ${TF_VAR_environment_id}"
echo -e "*** You can also access it via SSH with key located in ${ssh_path}"
echo -e "\e[0m"
;;
"destroy")
terraform destroy -input=false -auto-approve
rm /tmp/packet_id_rsa* || :

Copy link
Copy Markdown
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 ||?

;;
*)
echo "Use '$0 install' or '$0 destroy'."
;;
esac
19 changes: 19 additions & 0 deletions hack/prebuild/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#/bin/bash

yum install -y -d1 libvirt libvirt-daemon-kvm
usermod -aG libvirt root

Copy link
Copy Markdown
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
Copy Markdown
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.


cat <<EOF > /etc/libvirt/libvirtd.conf
unix_sock_group = "libvirt"
unix_sock_rw_perms = "0770"
listen_tls = 0
listen_tcp = 1
auth_tcp="none"
tcp_port = "16509"
EOF

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
Copy Markdown
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.

@enxebre enxebre Sep 27, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@paulfantom paulfantom Sep 27, 2018

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.


systemctl start libvirtd

Copy link
Copy Markdown
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
Copy Markdown
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.

32 changes: 32 additions & 0 deletions hack/prebuild/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "packet_project" "libvirt_actuator" {

@bison bison Sep 27, 2018

Copy link
Copy Markdown
Contributor

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.

name = "libvirt-actuator tests"

Copy link
Copy Markdown
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_ssh_key" "key" {
name = "unlikely_tf_ssh_key_name"

Copy link
Copy Markdown
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.

public_key = "${file("${var.ssh_key_path}")}"
}

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

Copy link
Copy Markdown
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.

plan = "baremetal_0"
facility = "ewr1"
operating_system = "centos_7"
billing_cycle = "hourly"
project_id = "${packet_project.libvirt_actuator.id}"
user_data = "#!/bin/bash\nsed -i 's/PasswordAuthentication.*$/PasswordAuthentication yes/g' /etc/ssh/sshd_config && systemctl restart sshd"
provisioner "remote-exec" {
script = "init.sh"
connection = {
type = "ssh"
user = "root"
password = "${self.root_password}"
agent = false
}
}
}

output "ip" {
value = "${packet_device.libvirt.access_public_ipv4}"
}

9 changes: 9 additions & 0 deletions hack/prebuild/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "ssh_key_path" {
type = "string"
default = "/tmp/packet_id_rsa.pub"
}

variable "environment_id" {
type = "string"
default = "testHypervisor"
}