Skip to content

Set keyUsage for generated HTTP certificates and self-signed CA #126376

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

Conversation

slobodanadamovic
Copy link
Contributor

@slobodanadamovic slobodanadamovic commented Apr 6, 2025

The elasticsearch-certutil http command, and security auto-configuration, generate the HTTP certificate and CA without setting the keyUsage extension.

This PR fixes this by setting (by default):

  • keyCertSign and cRLSign for self-signed CAs
  • digitalSignature and keyEncipherment for HTTP certificates and CSRs

These defaults can be overridden when running elasticsearch-certutil http command.
The user will be prompted to change them as they wish.

For elasticsearch-certutil ca, the default value can be overridden by passing the --keysage option, e.g.

elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem    

Fixes #117769

@slobodanadamovic slobodanadamovic added >bug :Security/TLS SSL/TLS, Certificates Team:Security Meta label for security team auto-backport Automatically create backport pull requests when merged v8.18.1 v8.19.0 v9.0.1 v9.1.0 v8.17.5 labels Apr 6, 2025
@slobodanadamovic slobodanadamovic self-assigned this Apr 6, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @slobodanadamovic, I've created a changelog YAML for you.

@slobodanadamovic slobodanadamovic requested a review from tvernum April 7, 2025 05:08
@slobodanadamovic slobodanadamovic marked this pull request as ready for review April 7, 2025 05:09
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Copy link
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

Did you consider whether elasticsearch-certutil ca should be changed?
It's typically not used as a HTTP ca, but our docs to show how it can be.

@slobodanadamovic
Copy link
Contributor Author

Did you consider whether elasticsearch-certutil ca should be changed?

Honestly, I haven't but it does make sense. I'll make it default to keyCertSign and cRLSign but also make it overridable if necessary.

@@ -347,7 +380,9 @@ static PKCS10CertificationRequest generateCSR(
if (sanList != null) {
extGen.addExtension(Extension.subjectAlternativeName, false, sanList);
}

if (keyUsage != null) {
extGen.addExtension(Extension.keyUsage, true, keyUsage);
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's debatable if CSR should include keyUsage. I went with adding it to the request and letting the issuer decide if it should be respected or not.

@@ -979,6 +1039,31 @@ private static Integer readKeySize(Terminal terminal, int keySize) {
});
}

private static List<String> readKeyUsage(Terminal terminal, List<String> defaultKeyUsage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current implementation of readKeyUsage will not allow users to remove the keyUsage, but rather only to change the default value. I think this is okay, otherwise it would defeat the purpose of adding it in the first place (but I may oversee a use case where this could be a requirement).

Let me know if you think we should allow it to be overridden to a "none".

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for http it's fine - I'm not even sure we need to let them change it.
If they want unlimited options they can use openssl (and suffer in pain)

@slobodanadamovic
Copy link
Contributor Author

@tvernum I've fixed the missed place to add key usage and also made the default key usage overridable when running both elasticsearch-certutil http and elasticsearch-certutil ca commands. Please take another look.

`does not have keyCertSign bit set in KeyUsage extension`
…danadamovic/elasticsearch into sa-include-key-usage-in-http-certs
@@ -979,6 +1039,31 @@ private static Integer readKeySize(Terminal terminal, int keySize) {
});
}

private static List<String> readKeyUsage(Terminal terminal, List<String> defaultKeyUsage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for http it's fine - I'm not even sure we need to let them change it.
If they want unlimited options they can use openssl (and suffer in pain)

@slobodanadamovic slobodanadamovic requested a review from tvernum April 8, 2025 06:30
Copy link
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks for the multiple rounds - it ended up being more than a 1 liner.

@slobodanadamovic slobodanadamovic merged commit 284121a into elastic:main Apr 8, 2025
22 checks passed
@elasticsearchmachine
Copy link
Collaborator

elasticsearchmachine commented Apr 8, 2025

💚 All backports created successfully

Status Branch Result
8.18
8.x
9.0
8.17

slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Apr 8, 2025
…astic#126376)

The `elasticsearch-certutil http` command, and security auto-configuration, 
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs 
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http` 
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing 
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem    
```

Fixes elastic#117769
@slobodanadamovic

This comment was marked as duplicate.

slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Apr 8, 2025
…astic#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes elastic#117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md
elasticsearchmachine pushed a commit that referenced this pull request Apr 8, 2025
…26376) (#126447)

The `elasticsearch-certutil http` command, and security auto-configuration, 
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs 
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http` 
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing 
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem    
```

Fixes #117769
elasticsearchmachine added a commit that referenced this pull request Apr 8, 2025
…26376) (#126448)

* Set `keyUsage` for generated HTTP certificates and self-signed CA (#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes #117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md

* fix compilation error

* [CI] Auto commit changes from spotless

* fix failing test

---------

Co-authored-by: elasticsearchmachine <[email protected]>
slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Apr 8, 2025
…astic#126376) (elastic#126448)

* Set `keyUsage` for generated HTTP certificates and self-signed CA (elastic#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes elastic#117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md

* fix compilation error

* [CI] Auto commit changes from spotless

* fix failing test

---------

Co-authored-by: elasticsearchmachine <[email protected]>
slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Apr 8, 2025
…astic#126376) (elastic#126448)

* Set `keyUsage` for generated HTTP certificates and self-signed CA (elastic#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes elastic#117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md

* fix compilation error

* [CI] Auto commit changes from spotless

* fix failing test

---------

Co-authored-by: elasticsearchmachine <[email protected]>
elasticsearchmachine added a commit that referenced this pull request Apr 8, 2025
…26376) (#126448) (#126454)

* Set `keyUsage` for generated HTTP certificates and self-signed CA (#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes #117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md

* fix compilation error

* [CI] Auto commit changes from spotless

* fix failing test

---------

Co-authored-by: elasticsearchmachine <[email protected]>
elasticsearchmachine added a commit that referenced this pull request Apr 8, 2025
…26376) (#126448) (#126453)

* Set `keyUsage` for generated HTTP certificates and self-signed CA (#126376)

The `elasticsearch-certutil http` command, and security auto-configuration,
generate the HTTP certificate and CA without setting the `keyUsage` extension.

This PR fixes this by setting (by default):
- `keyCertSign` and `cRLSign` for self-signed CAs
- `digitalSignature` and `keyEncipherment` for HTTP certificates and CSRs

These defaults can be overridden when running `elasticsearch-certutil http`
command. The user will be prompted to change them as they wish.

For `elasticsearch-certutil ca`, the default value can be overridden by passing
the `--keysage` option, e.g.
```
elasticsearch-certutil ca --keyusage "digitalSignature,keyCertSign,cRLSign" -pem
```

Fixes #117769

(cherry picked from commit 284121a)

# Conflicts:
#	docs/reference/elasticsearch/command-line-tools/certutil.md

* fix compilation error

* [CI] Auto commit changes from spotless

* fix failing test

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :Security/TLS SSL/TLS, Certificates Team:Security Meta label for security team v8.17.5 v8.18.1 v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elasticsearch CA certificates are rejected by Python 3.13
3 participants