Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

snp: added snp unencrypted test#5594

Merged
wainersm merged 9 commits into
kata-containers:CCv0from
ryansavino:add-snp-test
Jul 10, 2023
Merged

snp: added snp unencrypted test#5594
wainersm merged 9 commits into
kata-containers:CCv0from
ryansavino:add-snp-test

Conversation

@ryansavino
Copy link
Copy Markdown
Member

Fixes: #5593

added makefile target as well
moved common functions out of sev.bats
few minor fixes in separate commits

Signed-Off-By: Ryan Savino ryan.savino@amd.com

@katacontainersbot katacontainersbot added the size/huge Largest and most complex task (probably needs breaking into small pieces) label Apr 8, 2023
@katacontainersbot katacontainersbot added size/tiny Smallest and simplest task and removed size/huge Largest and most complex task (probably needs breaking into small pieces) labels Apr 9, 2023
Comment thread lib/common.bash Outdated
)
if [[ -z "${measurement}" ]]; then return 1; fi
echo ${measurement}
} No newline at end of file
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.

No newline at EOF

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

A few comments.

There may be some more code that could be shared with the non-tee tests, but I'm not sure it's worth getting into that given the impending merge and certain organizational issues with the tests.

I'm not very familiar with the stuff in .ci. Hopefully somoene else can help review those changes.

We will also need a new case in tests_runner.sh in the operator repo.

Comment thread lib/common.bash Outdated
# Delete all data with 'id = 10'
mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${kbs_db_host} -D ${KBS_DB} <<EOF
DELETE FROM secrets WHERE id = 10;
DELETE FROM keysets WHERE id = 10;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We shouldn't really have anything relating to keyses in the code anymore. I guess deleting them is fine as a precaution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread lib/common.bash Outdated

NAME="${name}" IMAGE="${image}" RUNTIMECLASS="${RUNTIMECLASS}" \
KBS_URI="${kbs_ip}:44444" \
POLICY="${policy}" \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setting the policy and kbs_uri via annoation is not supported for SNP. The annotations will just be ignored so it isn't too bad, but this function isn't quite as general as it might seem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

docker-compose \
cpuid
pip install sev-snp-measure
"${TESTS_REPO_DIR}/.ci/install_yq.sh" >&2
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not all of these are required currently. I don't think we use cpuid yet, for instance, since we don't calculate launch measurement. On the other hand maybe we should make these deps generic and move them to the common file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like the idea of maintaining the packages to be installed in the script that needs them. I added these packages in anticipation for when attestation tests would be added, but for now I've trimmed them down to what's required.

Comment thread lib/common.bash Outdated
# Extract name from the file name
local name=$(basename "${service_yaml%.*}")

# Default policy is 3:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only for SEV. SNP policies have different layout, but they don't get set here anyway (see below).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Resolved by other fix from above.

Copy link
Copy Markdown

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM with one little note.

Also, I think the lib code is probably in the wrong place, but I'm not sure what the optimal location is.

local initrd_path="$(esudo /opt/confidential-containers/bin/kata-runtime \
--config ${SEV_CONFIG} kata-env --json | jq -r .Initrd.Path)"
# Set the annotations for the simple-kbs URI and policy in the encrypted service yaml
encrypted_yaml_set_kbs_annotations() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be used for unencrypted images as well. It might be best to just have a yaml generation function for SEV and one for SNP. That is currently the fundamental difference in what annotations are available.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Are there any annotations we need to apply for the unencrypted?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The policy annotation is totally separate from whether the image is encrypted or not. The policy enables SEV-ES. It is totally valid to use -ES with an unencrypted image. The KBS URI isn't directly tied to encryption either, actually. You need to set that for signed images as well. So none of the annotations are directly related to whether the image is encrypted. That is determined by the format of the image itself. SEV and SNP do have different annotations as of today, though.

Copy link
Copy Markdown
Member Author

@ryansavino ryansavino Apr 18, 2023

Choose a reason for hiding this comment

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

Updated. Check it out now. I think this way might be better. Created a k8s_yaml_set_annotation method in common.bash and removed the specific method from sev.bats.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New approach is good.

@katacontainersbot katacontainersbot added size/huge Largest and most complex task (probably needs breaking into small pieces) and removed size/tiny Smallest and simplest task labels Apr 18, 2023
@UnmeshDeodhar UnmeshDeodhar force-pushed the add-snp-test branch 2 times, most recently from ec9ff8b to a08386a Compare May 2, 2023 22:15
@UnmeshDeodhar
Copy link
Copy Markdown

/test

@katacontainersbot katacontainersbot added size/tiny Smallest and simplest task size/huge Largest and most complex task (probably needs breaking into small pieces) and removed size/huge Largest and most complex task (probably needs breaking into small pieces) size/tiny Smallest and simplest task labels May 3, 2023
@UnmeshDeodhar
Copy link
Copy Markdown

/test-sev

@UnmeshDeodhar
Copy link
Copy Markdown

/test

1 similar comment
@UnmeshDeodhar
Copy link
Copy Markdown

/test

@katacontainersbot katacontainersbot removed the size/huge Largest and most complex task (probably needs breaking into small pieces) label May 12, 2023
This line is duplicate with line 19

Signed-Off-By: Ryan Savino <ryan.savino@amd.com>

Remove duplicate line
containerd config in /etc/containerd/config.toml requires sudo access

Signed-Off-By: Ryan Savino <ryan.savino@amd.com>
@UnmeshDeodhar UnmeshDeodhar force-pushed the add-snp-test branch 2 times, most recently from e657bc1 to 3b54502 Compare June 29, 2023 17:18
@ariel-adam
Copy link
Copy Markdown

@ryansavino is this on track for 0.7.0 (feature freeze 12th of July) or should we move it to 0.8.0?

Comment thread .ci/run.sh
info "Running Confidential Containers tests for AMD SEV"
sudo -E PATH="$PATH" CRI_RUNTIME="containerd" bash -c "make cc-sev-kubernetes"
;;
"CC_SNP_CRI_CONTAINERD_K8S")
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.

Sorry, just notice this CC_SNP_CRI_CONTAINERD_K8S.... usually we have CC_CRI_CONTAINERD_K8S_SOME_SPECIFIC_CONFIG. So it should be CC_CRI_CONTAINERD_K8S_SNP.

CC_SEV_CRI_CONTAINERD_K8S above seems wrong but better not change it right now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@wainersm changing this will need changes to be made in the CI repo as well. So do you think it is safer to do that in a different PR? I can open one as soon as this gets merged. I already have a PR open in ci repo. What do you think?

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.

@UnmeshDeodhar Indeed it is safer to do that change on a follow up PR.

@UnmeshDeodhar
Copy link
Copy Markdown

@ariel-adam, @ryansavino and I were on vacation this week so did not get a chance to reply. This is on track and I will incorporate all the feedback and get it ready before the merge. Will post something in the slack if I need someone's help to get it merged.

@katacontainersbot katacontainersbot added size/tiny Smallest and simplest task and removed size/huge Largest and most complex task (probably needs breaking into small pieces) size/tiny Smallest and simplest task labels Jul 7, 2023
common methods from sev.bats moved into common.bash
service.yaml.in generalized

Signed-Off-By: Ryan Savino <ryan.savino@amd.com>
Signed-Off-By: Unmesh Deodhar <udeodhar@amd.com>
@UnmeshDeodhar
Copy link
Copy Markdown

Thanks @wainersm for the review. I have addressed all your comments. Please let me know if this looks good now.

@UnmeshDeodhar
Copy link
Copy Markdown

/test


echo "Create the test sandbox"
echo "Pod config is: $pod_config"
kubernetes_create_cc_pod $pod_config
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.

Hi @UnmeshDeodhar , I prefer the other way around: change the name of the functions that you are introducing on this PR to Kubernetes_, and leave the existing non-snp tests untouched. I want to avoid any regressions on the exsiting tests at this point :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changed all the functions back to kubernetes_*

Comment thread .ci/install_qemu_experimental.sh Outdated

QEMU_PATH="/opt/kata/bin/qemu-system-x86_64-experimental"
if [ "${KATA_BUILD_QEMU_TYPE}" == "snp" ]; then
QEMU_PATH="/opt/confidential-containers/bin/qemu-system-x86_64-snp"
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.

In a VM where I ran this script I got the qemu for snp installed with another name:

$ crudini --get /opt/confidential-containers/share/defaults/kata-containers/configuration-qemu-snp.toml hypervisor.qemu path
"/opt/confidential-containers/bin/qemu-system-x86_64-snp-experimental"
$ ls /opt/confidential-containers/bin/
containerd-shim-kata-v2  kata-collect-data.sh  kata-monitor  kata-runtime  qemu-system-x86_64-snp-experimental

Maybe some code on this install_qemu_experimental.sh script is bogus?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good catch @wainersm.
I have removed the bogus code in build_qemu_experimental.sh

ryansavino and others added 6 commits July 7, 2023 17:32
added makefile target as well

Fixes: kata-containers#5593

Signed-Off-By: Ryan Savino <ryan.savino@amd.com>
Signed-Off-By: Unmesh Deodhar <udeodhar@amd.com>
Fixes: kata-containers#5593

Signed-off-by: Unmesh Deodhar <udeodhar@amd.com>
Fixes: kata-containers#5593

Signed-Off-By: Unmesh Deodhar <udeodhar@amd.com>
SNP requires generic OVMF. Thus adding a code that builds generic OVMF.

Fixes: kata-containers#5593

Signed-off-by: Unmesh Deodhar <udeodhar@amd.com>
Using pod annotation instead of changing the config file.

Fixes: kata-containers#5593

Signed-Off-By: Unmesh Deodhar <udeodhar@amd.com>
Renaming k8s_* functions to kubernetes_* to match the
rest of the functions.

Fixes: kata-containers#5593

Signed-Off-By: Unmesh Deodhar <udeodhar@amd.com>
@UnmeshDeodhar
Copy link
Copy Markdown

/test

1 similar comment
@UnmeshDeodhar
Copy link
Copy Markdown

/test

@fitzthum
Copy link
Copy Markdown

Last week there was some discussion about organizing this PR in a way that is easier to review or possibly splitting it into multiple. At this point I'm not really sure what would be most efficient, but let me make a few notes to help anyone who looks at this.

  • Commits 1 and 2 fix small miscellaneous issues in the SEV tests.
  • Commit 3 (the majority of the changes in this PR) extracts functions from the SEV tests that will also be used in the SNP test and moves them alongside some of the common code for the non-tee tests. This doesn't close all the gaps between the SEV tests and the non-tee tests, but it's a good start.
  • Commit 4 actually adds the SNP test, which is relatively simple.
  • Commits 5-9 fix SNP issues that snuck in during the merge from main to CCv0. It might have been better to put these in a separate PR. Since they are here, SNP will be broken until we can merge this. We could still move these into another PR, but it is getting pretty late in the day either way.

@wainersm
Copy link
Copy Markdown
Contributor

I see that in http://jenkins.katacontainers.io/job/tests-CCv0-ubuntu-20.04_snp-x86_64-CC_SNP_CRI_CONTAINERD_K8S-PR/64/consoleFull the SNP test introduced on this PR ran fine:

20:17:54 INFO: Run tests
20:17:54 1..1
20:18:21 ok 1 [cc][kubernetes][containerd][snp] Test SNP unencrypted container launch success
20:18:24 ~/workspace/tests-CCv0-ubuntu-20.04_snp-x86_64-CC_SNP_CRI_CONTAINERD_K8S-PR/go/src/github.com/kata-containers/tests

BTW, that job was manually created just to test this PR. It will be automatically created again once we get kata-containers/ci#547 merged (which depends on this PR).

One last thing before we merge this.... the TDX job failed. @fidencio could you please tell us the failure is related with this PR (or not)?

@wainersm
Copy link
Copy Markdown
Contributor

/test-tdx

Copy link
Copy Markdown
Contributor

@wainersm wainersm left a comment

Choose a reason for hiding this comment

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

@UnmeshDeodhar @ryansavino I think it can be merged now. Any improvement and fixes made to follow up PRs. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size/huge Largest and most complex task (probably needs breaking into small pieces)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants