Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

5.6 KB
Raw Blame
server {
    listen 80;

    # WebSocket endpoint for PAM web access
    location ~ ^/api/v1/pam/accounts/[^/]+/web-access$ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Disable buffering for real-time communication
        proxy_buffering off;
        proxy_cache off;

        # Increase timeouts for long-lived connections
        proxy_read_timeout 4200s;
        proxy_send_timeout 4200s;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    # Skill uploads accept up to 1MB of files (~1.37MB base64 + JSON on the wire).
    # Scoped to creating (POST /skills) and updating (PATCH /skills/:skillId) a skill, not all of /api.
    location ~ ^/api/v1/agent-vault/skills(/[^/]+)?/?$ {
        client_max_body_size 2M;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # This header is populated only by the dedicated TLS-cert-auth location.
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert "";

        proxy_pass http://backend:4000;
        proxy_redirect off;

        # proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    # KMS encrypt/decrypt/sign/verify accept payloads up to 1MB (~1.37MB base64 + JSON on the wire).
    # Scoped here so the larger body limit applies only to these endpoints, not all of /api.
    location ~ ^/api/v1/kms/keys/[^/]+/(encrypt|decrypt|sign|verify)$ {
        client_max_body_size 2M;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        # proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    location ~ ^/(api|secret-scanning/webhooks) {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        # proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    location /api/v3/migrate {
        client_max_body_size 25M;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    location /scep {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    location /.well-known/est {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Identity-Tls-Cert-Auth-Client-Cert $http_x_amzn_mtls_clientcert;

        # specific for infisical cloud setup, needed for server-side mTLS
        proxy_set_header X-SSL-Client-Cert $http_x_amzn_mtls_clientcert;

        proxy_pass http://backend:4000;
        proxy_redirect off;

        # proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
        proxy_cookie_path / "/; HttpOnly; SameSite=strict";
    }

    # location /git-app-api {
    #     proxy_set_header X-Real-IP $remote_addr;
    #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
    #     proxy_set_header Host $http_host;
    #     proxy_set_header X-NginX-Proxy true;

    #     proxy_pass http://git-app:3000/;
    #     proxy_redirect off;
    #     # proxy_redirect http://localhost:8080/ http://frontend.example.com/;

    #     proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
    # }

    location / {
        include /etc/nginx/mime.types;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_pass http://frontend:3000;
        proxy_redirect off;
    }
}