Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPsec key rotation command. #2266

Merged
merged 4 commits into from
Feb 6, 2024
Merged

IPsec key rotation command. #2266

merged 4 commits into from
Feb 6, 2024

Conversation

viktor-kurchenko
Copy link
Contributor

@viktor-kurchenko viktor-kurchenko commented Jan 27, 2024

encryption rotate-key command implementation to address: cilium/cilium#28174

Copy link
Member

@jschwinger233 jschwinger233 left a comment

Choose a reason for hiding this comment

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

Thanks Viktor, this PR really helps! Just one small issue on new SPI calculation.

encrypt/ipsec_rotate_key.go Show resolved Hide resolved
Copy link
Member

@jschwinger233 jschwinger233 left a comment

Choose a reason for hiding this comment

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

Thanks! Regarding the ipsecKeyFromString function, this PR takes care of keys like 3 rfc4106(gcm(aes)) 3c7ae6f6c0e9a09255fce39440df90619514709e 128. However, cilium can also accept a key with other formats.
I think these have been in your plan, just a reminder. 👍

@viktor-kurchenko
Copy link
Contributor Author

Thanks! Regarding the ipsecKeyFromString function, this PR takes care of keys like 3 rfc4106(gcm(aes)) 3c7ae6f6c0e9a09255fce39440df90619514709e 128. However, cilium can also accept a key with other formats. I think these have been in your plan, just a reminder. 👍

I've added other key format support.
Thank you very much @jschwinger233 !

Copy link
Member

@jschwinger233 jschwinger233 left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks Victor! A follow-up could be to support encryption algorithm change, such as from gcm(aes) to cbc(aes).

Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>

 Please enter the commit message for your changes. Lines starting

Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>
SPI suffix added to support SPI with `+` sign.
Tests added.

Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>
Copy link
Member

@asauber asauber left a comment

Choose a reason for hiding this comment

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

In the secret format with five fields,

3 hmac(sha256) e6b4bab427cd37bb64b39cd66a8476a62963174b78bc544fb525f4c2f548342b cbc(aes) 0f12337d9ee75095ff21402dc98476f5f9107261073b70bb37747237d2691d3e

the first field is the SPI, the second field is the authentication algorithm, the third field is the authentication key, the fourth field is the symmetric encryption mode, and the fifth field is the symmetric encryption key.

For symmetric encryption mode cbc(aes) means AES using the Cipher Block Chaining mode. There are many other valid algorithm choices and modes, such as ctr(aes), Counter Mode, or xctr(aes), an optimized implementation of Counter Mode. Other ciphers besides AES are also possible, although not available with typical kernel configs.

The reason that GCM has fewer parameters is that it's a mode of encryption that performs a hash and encipherment simultaneously.

All this is to say that your struct should not call the latter parameters cbcAlgo, and cbcRandom, these are the cipherMode and encryptionKey

@viktor-kurchenko
Copy link
Contributor Author

viktor-kurchenko commented Feb 1, 2024

In the secret format with five fields,

3 hmac(sha256) e6b4bab427cd37bb64b39cd66a8476a62963174b78bc544fb525f4c2f548342b cbc(aes) 0f12337d9ee75095ff21402dc98476f5f9107261073b70bb37747237d2691d3e

the first field is the SPI, the second field is the authentication algorithm, the third field is the authentication key, the fourth field is the symmetric encryption mode, and the fifth field is the symmetric encryption key.

For symmetric encryption mode cbc(aes) means AES using the Cipher Block Chaining mode. There are many other valid algorithm choices and modes, such as ctr(aes), Counter Mode, or xctr(aes), an optimized implementation of Counter Mode. Other ciphers besides AES are also possible, although not available with typical kernel configs.

The reason that GCM has fewer parameters is that it's a mode of encryption that performs a hash and encipherment simultaneously.

All this is to say that your struct should not call the latter parameters cbcAlgo, and cbcRandom, these are the cipherMode and encryptionKey

Thank you for the explanation @asauber.
So, the structure should look like:

type ipsecKey struct {
	spi       int
	spiSuffix bool
	algo      string
	random    string
	size      int
	cipherMode   string
	encryptionKey string
}

correct?

@asauber
Copy link
Member

asauber commented Feb 1, 2024

My recommendation would be:

type ipsecKey struct {
	spi          int
	spiSuffix    bool
	algo         string  // Purposefully ambiguous here because of modes like GCM
	key          string
	size         int
	cipherMode   string
	cipherKey    string
}

@viktor-kurchenko
Copy link
Contributor Author

My recommendation would be:

type ipsecKey struct {
	spi          int
	spiSuffix    bool
	algo         string  // Purposefully ambiguous here because of modes like GCM
	key          string
	size         int
	cipherMode   string
	cipherKey    string
}

Fixed, thank you!

return key, nil
}

func cbcKeyFromSlice(parts []string) (ipsecKey, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This function name (and other instances of "cbc") should be changed to cipherKeyFromSlice or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}

var (
ipsecKeyRegex = regexp.MustCompile(`^([[:digit:]]+\+?)[[:space:]](\S+)[[:space:]]([[:alnum:]]+)[[:space:]]([[:digit:]]+)$`)
Copy link
Member

@asauber asauber Feb 6, 2024

Choose a reason for hiding this comment

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

Many security issues (CVEs) are the result of imprecise parsing, with Regex often being implicated.

The related threat model here is that an attacker can somehow control the ipsec key Kubernetes secret, which may make such hardening out of scope, although it is something that should be considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, do you think we should avoid using regexp and parse it like a CSV string instead?

Copy link
Member

Choose a reason for hiding this comment

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

My gut feeling is that this is more precise than a simple field split, and is fine for now given the threat model.

return newKey, nil
}

func generateRandom(size int) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Because this size is the length of a hex string, and not a number of bytes, this function is better named generateRandomHex. Otherwise, it's unclear that the size is a number of nybbles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, renamed. Thank you!

Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>
Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>
@viktor-kurchenko viktor-kurchenko added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Feb 6, 2024
@tklauser tklauser merged commit 17bb086 into main Feb 6, 2024
13 checks passed
@tklauser tklauser deleted the pr/vk/encryption/rotate-key branch February 6, 2024 14:13
aanm pushed a commit to aanm/cilium that referenced this pull request Mar 7, 2024
GitHub Pull Request: #623

chore(deps): update dependency cilium/cilium-cli to v0.15.23 (v1.15)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [cilium/cilium-cli](https://togithub.com/cilium/cilium-cli) |  | patch | `v0.15.22` -> `v0.15.23` |
| [cilium/cilium-cli](https://togithub.com/cilium/cilium-cli) | action | patch | `v0.15.22` -> `v0.15.23` |

---

### Release Notes

<details>
<summary>cilium/cilium-cli (cilium/cilium-cli)</summary>

### [`v0.15.23`](https://togithub.com/cilium/cilium-cli/releases/tag/v0.15.23)

[Compare Source](https://togithub.com/cilium/cilium-cli/compare/v0.15.22...v0.15.23)

#### What's Changed

-   gateway: Upgrade API version by [@&cilium#8203;sayboras](https://togithub.com/sayboras) in [cilium/cilium-cli#2285
-   chore(deps): update dependency kubernetes-sigs/kind to v0.21.0 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2284
-   IPsec key rotation command. by [@&cilium#8203;viktor-kurchenko](https://togithub.com/viktor-kurchenko) in [cilium/cilium-cli#2266
-   IPsec key status command implementation. by [@&cilium#8203;viktor-kurchenko](https://togithub.com/viktor-kurchenko) in [cilium/cilium-cli#2287
-   AWS OIDC instead of access key. by [@&cilium#8203;viktor-kurchenko](https://togithub.com/viktor-kurchenko) in [cilium/cilium-cli#2297
-   Remove no longer necessary step from the external workloads installation script generation process by [@&cilium#8203;giorio94](https://togithub.com/giorio94) in [cilium/cilium-cli#2275
-   Enable no-errors-in-logs check by default, and extend it to all Cilium components by [@&cilium#8203;giorio94](https://togithub.com/giorio94) in [cilium/cilium-cli#2184
-   chore(deps): update golangci/golangci-lint-action action to v4 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2295
-   chore(deps): update helm/kind-action action to v1.9.0 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2296
-   chore(deps): update golang docker tag to v1.22.0 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2289
-   fix(deps): update module golang.org/x/mod to v0.15.0 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2294
-   chore(deps): update go to v1.22.0 (minor) by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2293
-   chore(deps): update all github action dependencies (patch) by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2286
-   chore(deps): update golangci/golangci-lint docker tag to v1.56.1 by [@&cilium#8203;renovate](https://togithub.com/renovate) in [cilium/cilium-cli#2290
-   IPsec key rotation with algorithm change support. by [@&cilium#8203;viktor-kurchenko](https://togithub.com/viktor-kurchenko) in [cilium/cilium-cli#2291
-   chore: Amend connectivity tests for OpenShift by [@&cilium#8203;fgiloux](https://togithub.com/fgiloux) in [cilium/cilium-cli#2303
-   Increase timeouts in AKS and GKE GHA workflows by [@&cilium#8203;giorio94](https://togithub.com/giorio94) in [cilium/cilium-cli#2307
-   gha: increase GKE disk size in external workloads workflow to 15GB by [@&cilium#8203;giorio94](https://togithub.com/giorio94) in [cilium/cilium-cli#2301
-   Prepare for v0.15.23 release by [@&cilium#8203;michi-covalent](https://togithub.com/michi-covalent) in [cilium/cilium-cli#2302

#### New Contributors

-   [@&cilium#8203;fgiloux](https://togithub.com/fgiloux) made their first contribution in [cilium/cilium-cli#2303

**Full Changelog**: cilium/cilium-cli@v0.15.22...v0.15.23

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on monday" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/aanm/cilium).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMjAuMiIsInVwZGF0ZWRJblZlciI6IjM3LjIyMC4yIiwidGFyZ2V0QnJhbmNoIjoidjEuMTUifQ==-->


Patch-set: 1
Change-id: I515325620aa4905df61d31323487f6936237e3a5
Subject: chore(deps): update dependency cilium/cilium-cli to v0.15.23
Branch: refs/heads/v1.15
Status: new
Topic: 
Commit: 7c37f7d
Tag: autogenerated:gerrit:newPatchSet
Groups: 7c37f7d
Private: false
Work-in-progress: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants