Skip to content

Add TLS standardization for platform, mongo, gateway & redis roles#300

Open
Amunagala-itential wants to merge 5 commits intoitential:feature/v4from
Amunagala-itential:feature/v4-tls-changes
Open

Add TLS standardization for platform, mongo, gateway & redis roles#300
Amunagala-itential wants to merge 5 commits intoitential:feature/v4from
Amunagala-itential:feature/v4-tls-changes

Conversation

@Amunagala-itential
Copy link
Contributor

PKI Standardization and Hostname-Based Certificate Support

Summary

Standardized PKI implementation across MongoDB, Redis, Platform, and Gateway roles with hostname-based certificate naming to support multi-server deployments with unique certificates per host.

Problem

  • Hardcoded certificate names (server.pem, redis.crt) prevented multi-server deployments
  • Inconsistent PKI paths across roles (/etc/ssl/, /opt/itential/)
  • No flexible certificate strategy support (per-host, per-role, wildcard)

Solution

  • Hostname-based certificate naming using {{ inventory_hostname }}
  • Standardized PKI directory structure (/etc/pki/*)
  • Comprehensive PKI variables for all roles
  • Certificate preparation automation script
  • Support for 3 deployment scenarios via configuration

Comment on lines +93 to +101
# ============================================================================
# Backward Compatibility - Legacy Variable Names
# These maintain compatibility with existing templates
# ============================================================================

# Legacy variables for templates (point to new paths)
gateway_ssl_cert_dest: "{{ gateway_https_cert_file }}"
gateway_ssl_key_dest: "{{ gateway_https_key_file }}"
gateway_ssl_rootca_dest: "{{ gateway_https_ca_file }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to provide backwards compatibility. Update the templates with the new variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since you are using the same tags for all tasks, use a task block and move the tags to the block.

Comment on lines 30 to 31
# and allows the use of invalid or self-signed certificates to connect.
platform_mongo_tls_allow_invalid_certificates: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be moved to the pki defaults file?

Choose a reason for hiding this comment

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

I vote we keep it here. Ultimately, its used in the mongo config file template only.

# ============================================================================

# Source directory for HTTPS certificates (on Ansible controller)
platform_https_pki_src_dir: "/Users/ananth.munagala/deployer_checkins/PE-1386/certificates/platform"
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 this needs to change...

Choose a reason for hiding this comment

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

This is why we do code reviews. :-)

platform_https_pki_src_dir: "/Users/ananth.munagala/deployer_checkins/PE-1386/certificates/platform"

# Source directory for MongoDB certificates (on Ansible controller)
platform_mongodb_pki_src_dir: "/Users/ananth.munagala/deployer_checkins/PE-1386/certificates/platform"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

Use block for tags

| `gateway_https_cert_filename` | String | HTTPS certificate filename. | `{{ inventory_hostname }}.crt` |
| `gateway_https_key_filename` | String | HTTPS private key filename. | `{{ inventory_hostname }}.key` |
| `gateway_https_ca_filename` | String | HTTPS CA bundle filename. | `ca-bundle.crt` |
| `gateway_pki_src_dir` | String | Source directory for Gateway certificates (on Ansible controller). | (set in inventory) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| `gateway_pki_src_dir` | String | Source directory for Gateway certificates (on Ansible controller). | (set in inventory) |
| `gateway_pki_src_dir` | String | Source directory for Gateway certificates (on Ansible controller). | MUST be set in inventory |

| `gateway_https_ca_filename` | String | HTTPS CA bundle filename. | `ca-bundle.crt` |
| `gateway_pki_src_dir` | String | Source directory for Gateway certificates (on Ansible controller). | (set in inventory) |
| `gateway_https_cert_file` | String | Deployed HTTPS certificate path. | `{{ gateway_pki_https_dir }}/{{ gateway_https_cert_filename }}` |
| `gateway_https_key_file` | String | Deployed HTTPS private key path. | `{{ gateway_pki_private_dir }}/{{ gateway_https_key_filename }}` |
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see gateway_pki_private_dir.

Comment on lines +495 to +500
certificates/
├── platform
│   ├── ca-bundle.crt
│   ├── ip-10-222-1-169.ec2.internal.crt
│   ├── ip-10-222-1-64.ec2.internal.crt
│   ├── ip-10-222-1-64.ec2.internal.key
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't render correctly.

Choose a reason for hiding this comment

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

I think it needs the ```

Comment on lines +166 to +172
certificates/
├── mongodb
│   ├── ca-bundle.crt
│   ├── hostname1.pem
│   ├── hostname2.pem
│   ├── hostname3.pem
│   ├── replica.key
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably doesn't render correctly either.

|----------|----------|---------------------|
| **Scenario 1** | Per-host certificates (most secure) | One unique cert per server |
| **Scenario 2** | Per-role certificates (simplified management) | One cert shared per role |
| **Scenario 3** | Single wildcard certificate (simplest) | One cert for everything |
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be wrong, but a multi-domain cert and a wild-card cert aren't synonymous. You can have a MD cert with actual hostnames. Or you can have a MD wild-card cert. Maybe just call this "Multi-Domain certificate".

Choose a reason for hiding this comment

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

Correct. A multi-domain cert can list many DNS or IPs in it, one file suitable for many servers. A wildcard cert uses a * in the DNS names, which also makes it suitable for many servers but its easier to spoof and depends on regex. I would call these multi-domain certs.

Comment on lines +268 to +280
## Recommendations by Environment

### Development/Testing
- **Use:** Scenario 3 (Wildcard)
- **Why:** Simplest, fastest to set up, easy to regenerate

### Staging
- **Use:** Scenario 2 (Per-Role)
- **Why:** Balance of simplicity and security, mirrors production patterns

### Production
- **Use:** Scenario 1 (Per-Host)
- **Why:** Best security, compliance requirements, limited blast radius
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we want to provide recommendations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I have removed the recommendations section

group: "{{ gateway_pki_group }}"
mode: "{{ gateway_pki_subdir_mode }}"
loop:
- "{{ gateway_pki_https_dir }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need a loop here.

# Set this in your inventory to point to your certificate directory
mongodb_pki_src_dir: ""

mongodb_ssl_root_dir: "{{ mongodb_pki_base_dir }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove and replace references with mongodb_pki_base_dir

platform_pki_base_owner: root

# Group for PKI base directory
platform_pki_base_group: itential
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
platform_pki_base_group: itential
platform_pki_base_group: "{{ platform_group }}"

platform_pki_private_owner: root

# Group for private key files
platform_pki_private_group: itential
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
platform_pki_private_group: itential
platform_pki_private_group: "{{ platform_group }}"

Copy link
Contributor

Choose a reason for hiding this comment

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

There are also some changes I anticipate to set the appropriate SE Linux labels on files. We can address that separately.

Comment on lines +495 to +500
certificates/
├── platform
│   ├── ca-bundle.crt
│   ├── ip-10-222-1-169.ec2.internal.crt
│   ├── ip-10-222-1-64.ec2.internal.crt
│   ├── ip-10-222-1-64.ec2.internal.key

Choose a reason for hiding this comment

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

I think it needs the ```

|----------|----------|---------------------|
| **Scenario 1** | Per-host certificates (most secure) | One unique cert per server |
| **Scenario 2** | Per-role certificates (simplified management) | One cert shared per role |
| **Scenario 3** | Single wildcard certificate (simplest) | One cert for everything |

Choose a reason for hiding this comment

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

Correct. A multi-domain cert can list many DNS or IPs in it, one file suitable for many servers. A wildcard cert uses a * in the DNS names, which also makes it suitable for many servers but its easier to spoof and depends on regex. I would call these multi-domain certs.

Comment on lines +155 to +156
├── wildcard.crt ← One cert for everything
├── wildcard.key

Choose a reason for hiding this comment

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

+1

gateway_pki_owner: "{{ gateway_user }}"

# Group for PKI directories and files
gateway_pki_group: "{{ gateway_group }}"

Choose a reason for hiding this comment

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

I'm not sure what value these two vars provide. We should be opinionated in the tasks that create make these files and user the gateway_user and gateway_group. If that's not sufficient for customers then they can change it after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, gateway_pki_owner and gateway_pki_group are just wrappers around gateway_user and gateway_group with no added value.
I have used gateway_user and gateway_group in the tasks directly.

gateway_https_key_mode: "0600"

# HTTPS CA bundle permissions
gateway_https_ca_mode: "0644"

Choose a reason for hiding this comment

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

I'm not sure what values these provide either. Lets just set the permissions in the tasks and reduce the complexity here. Or move these vars where they can not be overridden.

Comment on lines 30 to 31
# and allows the use of invalid or self-signed certificates to connect.
platform_mongo_tls_allow_invalid_certificates: false

Choose a reason for hiding this comment

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

I vote we keep it here. Ultimately, its used in the mongo config file template only.

# ============================================================================

# Source directory for HTTPS certificates (on Ansible controller)
platform_https_pki_src_dir: "/Users/ananth.munagala/deployer_checkins/PE-1386/certificates/platform"

Choose a reason for hiding this comment

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

This is why we do code reviews. :-)

platform_root_dir: "{{ platform_root_dir_default }}"
platform_config_dir: "{{ platform_config_dir_default }}"
platform_tls_dir: "{{ platform_tls_dir_default }}"
# platform_tls_dir: "{{ platform_tls_dir_default }}"

Choose a reason for hiding this comment

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

If we don't need it then remove it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments