Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Upstream: fixed passwords support for dynamic certificates. #528

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

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

pluknet
Copy link
Contributor

@pluknet pluknet commented Feb 17, 2025

Passwords were not preserved in optimized SSL contexts, the bug had
appeared in d791b4a (1.23.1), as in the following configuration:

server {
    proxy_ssl_password_file password;
    proxy_ssl_certificate $ssl_server_name.crt;
    proxy_ssl_certificate_key $ssl_server_name.key;

    location /original/ {
        proxy_pass https://u1/;
    }

    location /optimized/ {
        proxy_pass https://u2/;
    }
}

The fix is to always preserve passwords, by copying to the configuration
pool, if dynamic certificates are used. This is done as part of merging
"ssl_passwords" configuration.

To minimize the number of copies, a preserved version is then used for
inheritance. A notable exception is inheritance of preserved empty
passwords to the context with statically configured certificates:

server {
    proxy_ssl_certificate $ssl_server_name.crt;
    proxy_ssl_certificate_key $ssl_server_name.key;

    location / {
        proxy_pass ...;

        proxy_ssl_certificate example.com.crt;
        proxy_ssl_certificate_key example.com.key;
    }
}

In this case, an unmodified version (NULL) of empty passwords is set,
to allow reading them from the password prompt on nginx startup.

As an additional optimization, a preserved instance of inherited
configured passwords is set to the previous level, to inherit it
to other contexts:

server {
    proxy_ssl_password_file password;

    location /1/ {
        proxy_pass https://u1/;
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;
    }

    location /2/ {
        proxy_pass https://u2/;
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;
    }
}

@pluknet
Copy link
Contributor Author

pluknet commented Feb 17, 2025

Alternative to #458 (which doesn't try to minimize the number of preserved copies) and #471 (alters internal parts of ngx_event_openssl.c in unclean fashion).

@pluknet pluknet requested review from arut and bavshin-f5 March 4, 2025 19:28
@Maryna-f5 Maryna-f5 added this to the nginx-1.27.5 milestone Apr 7, 2025
@pluknet
Copy link
Contributor Author

pluknet commented Apr 7, 2025

Updated commit log with clarifications, added one more example.

@pluknet pluknet force-pushed the set_ssl4 branch 4 times, most recently from b91d4b3 to 5d3c24f Compare April 8, 2025 14:01
Passwords were not preserved in optimized SSL contexts, the bug had
appeared in d791b4a (1.23.1), as in the following configuration:

    server {
        proxy_ssl_password_file password;
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;

        location /original/ {
            proxy_pass https://u1/;
        }

        location /optimized/ {
            proxy_pass https://u2/;
        }
    }

The fix is to always preserve passwords, by copying to the configuration
pool, if dynamic certificates are used.  This is done as part of merging
"ssl_passwords" configuration.

To minimize the number of copies, a preserved version is then used for
inheritance.  A notable exception is inheritance of preserved empty
passwords to the context with statically configured certificates:

    server {
        proxy_ssl_certificate $ssl_server_name.crt;
        proxy_ssl_certificate_key $ssl_server_name.key;

        location / {
            proxy_pass ...;

            proxy_ssl_certificate example.com.crt;
            proxy_ssl_certificate_key example.com.key;
        }
    }

In this case, an unmodified version (NULL) of empty passwords is set,
to allow reading them from the password prompt on nginx startup.

As an additional optimization, a preserved instance of inherited
configured passwords is set to the previous level, to inherit it
to other contexts:

    server {
        proxy_ssl_password_file password;

        location /1/ {
            proxy_pass https://u1/;
            proxy_ssl_certificate $ssl_server_name.crt;
            proxy_ssl_certificate_key $ssl_server_name.key;
        }

        location /2/ {
            proxy_pass https://u2/;
            proxy_ssl_certificate $ssl_server_name.crt;
            proxy_ssl_certificate_key $ssl_server_name.key;
        }
    }
@pluknet
Copy link
Contributor Author

pluknet commented Apr 8, 2025

Simplified merge functions, added code comments.

Copy link
Contributor

@arut arut left a comment

Choose a reason for hiding this comment

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

Reviewed the code and tested. Looks good to me.

@pluknet pluknet merged commit 6c3a9d5 into nginx:master Apr 10, 2025
1 check passed
@pluknet pluknet deleted the set_ssl4 branch April 10, 2025 13:27
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