31 Nginx & Odoo. Pasar datos del certificado a Odoo
1. Modificar la configuración de nginx
Vamos a fjarnos en esta entrada para ver como se pasan datos del certificado a odoo desde nginx
Para ello modiicamos el de configuración de nginx a este otro. Recordar que la configuración de nginx estaba en /etc/nginx/sites-enabled/default. Veamos que se ha hecho:
1. Se ha añadido una nueva ruta "/prova" que se entra por https://localhost:8443:/prova
2. Se redirige desde /prova a /library/catalog y se le passan como parámetros:
&DN=$ssl_client_s_dn #Distinguished name del certificado cliente
&verify=$ssl_client_verify #Si el certificado ha sido verificado
&server=$remote_addr redirect #Dirección del server
3. Por tanto la idea es que al llamar a la URL https://localhost:8443:/prova nos redirija a https://localhost:8443:/library/catalog?DN=crtificado_DN&veryfy=SUCCESS%server=127.0.0.1
upstream odoo { server 127.0.0.1:8069; } upstream odoochat { server 127.0.0.1:8072; } server { listen 80; server_name odoo.example.com; proxy_read_timeout 720s; proxy_connect_timeout 720s; proxy_send_timeout 720s; # Add Headers for odoo proxy mode proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; # log access_log /var/log/nginx/odoo.access.log; error_log /var/log/nginx/odoo.error.log; # Redirect longpoll requests to odoo longpolling port location /longpolling { proxy_pass http://odoochat; } # Redirect requests to odoo backend server location / { proxy_redirect off; proxy_pass http://odoo; } #status page*******************************************+ location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; # Only allow requests from localhost deny all; # Deny all other requests } # common gzip gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript; gzip on; } #https server { listen 8443 ssl; server_name odoo.example.com; ssl_certificate /home/ximo/MyCerts/2024/webserver.crt ssl_certificate_key /home/ximo/MyCerts/2024/webserver.key;
ssl_client_certificate /home/ximo/MyCerts/2024/myCA.pem;
#ssl_verify_client optional_no_ca; #NO VA ssl_verify_client on; #VA si no afafem certificat #ssl_verify_depth 3; proxy_set_header X-SSL-CERT $ssl_client_escaped_cert; access_log /var/log/nginx/odoo.example.access.log; error_log /var/log/nginx/odoo.example.error.log; #status page*******************************************+ location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; # Only allow requests from localhost deny all; # Deny all other requests }location = /prova { if ($arg_verify = "") { #@see https://serverfault.com/q/1112066/986686 #flags: redirect and permanent change externally the URL but produces loops #flags: last, break and no flag change only internally, and the browser is not affected # so use redirect or permanent trying to avoid loops with an if statement rewrite ^ /library/catalog?DN=$ssl_client_s_dn&verify=$ssl_client_verify&server=$remote_addr redirect; } try_files /index.html =404; } location / { proxy_pass http://127.0.0.1:8069;
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } }
2. Crear un controlador a a ruta /library/catalog
Aprovechamos el código de Daniel Reis del capítulo 13 y modificamos el controlador main.py del módulo "library_portal" y le dejamos con est código
odoo import http class Main(http.Controller): @http.route("/library/catalog", auth="public", website=True) def catalog(self, **kwargs): Book = http.request.env["library.book"] books = Book.sudo().search([]) # Get parameters from the request param_DN = kwargs.get('DN') param_verify = kwargs.get('cerify') param_server = kwargs.get('server') res = http.request.render( "library_portal.book_catalog", {"books": books}, ) #return res print(f"Parameters received: param1={param_DN}, param2={param_verify}, param3={param_server}") return http.request.make_response(f"Parameters received: param1={param_DN}, param2={param_verify}, param3={param_server}")
Con ello ya podemos dar un uso de dichos parámetros.
Observar que en la línea marcada en verde claro hemos indicada auth="public" cosa que permite entrar a todo el mundo aquí, pero por software vamos a permitirles hacer unas cosas u otras en función de los valores del certificado.
En este caso nos muestra
Comentarios
Publicar un comentario