{"id":397062,"date":"2024-06-29T13:13:28","date_gmt":"2024-06-29T13:13:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=397062"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T13:13:28","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=397062","title":{"rendered":"<span>Google SSO for Kibana straightforward way on basic license<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>As many times before, I keep writing cheat sheets after the tasks which made me search a lot and glue things together before I found a solution. Long story short, this time I was asked to set up Google SSO for Kibana without switching from a basic license to a paid one. Kibana, by the moment, already had authentication set up and the\u00a0customer wanted to log in there with the use of Google Workspace user accounts. Along with that, the customer wanted to keep user\u00a0account which was\u00a0already there, in Kibana. There was no need for role mapping or other advanced features, just plain SSO and that&#8217;s all. As you probably know Elastic provides SSO feature only on paid license, so I have had no other way to get it working except for using 3rd party software. But first things first, let&#8217;s list the steps we should\u00a0go over:<\/p>\n<ol>\n<li>\n<p>Create credentials for the application in GCP Console<\/p>\n<\/li>\n<li>\n<p>Install and set up oauth2-proxy<\/p>\n<\/li>\n<li>\n<p>Set up Nginx<\/p>\n<\/li>\n<\/ol>\n<p>Now let&#8217;s dig into the details.<\/p>\n<h2>Presumptions<\/h2>\n<blockquote>\n<p>Kibana&#8217;s\u00a0url:\u00a0<a href=\"https:\/\/kibana.example.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com<\/a><\/p>\n<p>Username for logging into Kibana: <strong>kibana<\/strong><\/p>\n<p>Password for user <code>kibana<\/code>: <strong>$3cuRep@sSW0rd<\/strong><\/p>\n<p>Nginx is set up and used for reverse-proxying Kibana<\/p>\n<\/blockquote>\n<h2>Getting credentials for authentication at GCP  <\/h2>\n<p>Navigate to\u00a0<a href=\"https:\/\/console.cloud.google.com\/apis\/credentials\" rel=\"noopener noreferrer nofollow\">https:\/\/console.cloud.google.com\/apis\/credentials<\/a><\/p>\n<details class=\"spoiler\">\n<summary>If you don&#8217;t have any GCP project yet, you should create one<\/summary>\n<div class=\"spoiler__content\">\n<p>You can refer to the documentation on the topic\u00a0<a href=\"https:\/\/cloud.google.com\/resource-manager\/docs\/creating-managing-projects\" rel=\"noopener noreferrer nofollow\">https:\/\/cloud.google.com\/resource-manager\/docs\/creating-managing-projects<\/a><\/p>\n<p>Don&#8217;t forget to add authorized email domains which users will be allowed to log into Kibana. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/566\/cb0\/3bd\/566cb03bde5f5c8047010bc968115560.png\" width=\"551\" height=\"245\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/566\/cb0\/3bd\/566cb03bde5f5c8047010bc968115560.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/206\/32d\/680\/20632d680589ec4be13e7e55ac9469f5.png\" width=\"744\" height=\"471\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/206\/32d\/680\/20632d680589ec4be13e7e55ac9469f5.png\"\/><\/figure>\n<p>On the next page select <code>Application type<\/code> as Web application, <code>Name<\/code> could be any of your preferences, then put URLs of your Kibana as follows:<\/p>\n<ul>\n<li>\n<p>Base URL of your Kibana for\u00a0<code>Authorized JavaScript origins<\/code>:\u00a0<a href=\"https:\/\/kibana.example.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com<\/a><\/p>\n<\/li>\n<li>\n<p>Route to Kibana&#8217;s oauth2 callbacks for\u00a0<code>Authorized redirect URIs<\/code>: <a href=\"https:\/\/kibana.example.com\/oauth2\/callback\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com\/oauth2\/callback<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/420\/d8c\/e96\/420d8ce96bcbb26693bf222982e21f38.png\" width=\"568\" height=\"912\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/420\/d8c\/e96\/420d8ce96bcbb26693bf222982e21f38.png\"\/><\/figure>\n<p>Click Create and take a note on the contents of the pop-up window after. Copy and save\u00a0<code>Client\u00a0ID<\/code>\u00a0and\u00a0<code>Client secret<\/code>\u00a0as we will need them a bit later.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5a0\/85d\/b75\/5a085db75b7228c8048005fe3a8bbfaf.png\" width=\"523\" height=\"559\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a0\/85d\/b75\/5a085db75b7228c8048005fe3a8bbfaf.png\"\/><\/figure>\n<\/li>\n<\/ul>\n<h2>Setting up oauth2-proxy<\/h2>\n<p>Since ELK is running in Docker containers on the customer&#8217;s side, I decided to use <strong>oauth2-proxy<\/strong> in the container too. But before we run <strong>oauth2-proxy<\/strong> we need to generate value for\u00a0<code>OAUTH2_PROXY_COOKIE_SECRET<\/code> parameter.<\/p>\n<p>Execute the command:<\/p>\n<pre><code class=\"bash\">python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())'<\/code><\/pre>\n<p>Save the resulting value, for example we will take this one\u00a0<code>HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=<\/code><\/p>\n<p>Now we are good to go. There are a number of ways to configure <strong>oauth2-proxy<\/strong> and I choose to do that over environmental variables. Run the container and pass variables and its values with use of\u00a0<code>-e<\/code>\u00a0parameter:<\/p>\n<pre><code class=\"bash\">docker run -d --name oauth2-proxy -p 1080:1080 -p 1443:1443 \\        -e \"OAUTH2_PROXY_COOKIE_SECRET=HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=\" \\        -e \"OAUTH2_PROXY_PROVIDER=google\" \\        -e \"OAUTH2_PROXY_EMAIL_DOMAINS=*\" \\        -e \"OAUTH2_PROXY_CLIENT_ID=848148116345-nphihtsirct0807h85fen01b69si3s9v.apps.googleusercontent.com\" \\        -e \"OAUTH2_PROXY_CLIENT_SECRET=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\" \\        -e \"OAUTH2_PROXY_HTTP_ADDRESS=0.0.0.0:1080\" \\        -e \"OAUTH2_PROXY_UPSTREAMS=https:\/\/kibana.example.com\" \\        quay.io\/oauth2-proxy\/oauth2-proxy:v7.4.0-amd64<\/code><\/pre>\n<blockquote>\n<p>Don&#8217;t forget to put actual values for <code>secrets<\/code> and <code>Client ID<\/code> you got yourself on previous steps instead of the ones I used for writing the examples!<\/p>\n<\/blockquote>\n<p>Check if container&#8217;s status is Up by executing the command:<\/p>\n<pre><code class=\"bash\">docker ps<\/code><\/pre>\n<p>If you prefer docker compose you can use the following <code>yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">version: \"3.2\" services:   oauth2-proxy:     container_name: oauth2-proxy     image: quay.io\/oauth2-proxy\/oauth2-proxy:v7.4.0-amd64     ports:       - \"1080:1080\"       - \"1443:1443\"     environment:       OAUTH2_PROXY_COOKIE_SECRET: \" HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=\"       OAUTH2_PROXY_PROVIDER: \"google\"       OAUTH2_PROXY_EMAIL_DOMAINS: \"*\"       OAUTH2_PROXY_CLIENT_ID: \" 848148116345-nphihtsirct0807h85fen01b69si3s9v.apps.googleusercontent.com  \"       OAUTH2_PROXY_CLIENT_SECRET: \" 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  \"       OAUTH2_PROXY_HTTP_ADDRESS: \"0.0.0.0:1080\"       OAUTH2_PROXY_UPSTREAMS: \" https:\/\/kibana.example.com\"<\/code><\/pre>\n<p>As for me, all the parameters are self-explanatory but you can refer to the official docs at any time:\u00a0<a href=\"https:\/\/oauth2-proxy.github.io\/oauth2-proxy\/docs\/configuration\/overview\/\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth2-proxy.github.io\/oauth2-proxy\/docs\/configuration\/overview\/<\/a><\/p>\n<p>Check if newly created container is up and oauth2-proxy is running and returns html on requests:<\/p>\n<pre><code class=\"bash\">curl localhost:1080<\/code><\/pre>\n<p>If you get something like that then we are good to go to the next step:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/de1\/455\/245\/de1455245fcf2cba3af8dbb80830110f.png\" width=\"1180\" height=\"1018\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/de1\/455\/245\/de1455245fcf2cba3af8dbb80830110f.png\"\/><\/figure>\n<p>You can navigate to\u00a0<a href=\"http:\/\/localhost:1080\/\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:1080<\/a>\u00a0in a browser of your choice as well and check if loaded page looks like that:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c08\/577\/7ca\/c085777caf65abb71badae094046b9bf.png\" width=\"418\" height=\"492\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c08\/577\/7ca\/c085777caf65abb71badae094046b9bf.png\"\/><\/figure>\n<h2>Modifying Nginx&#8217;s config<\/h2>\n<p>As we assumed before, we use Nginx as a reverse-proxy for Kibana. It means that a minimal configuration of <code>\/<\/code> location is set up and now it&#8217;s time to add a couple of new lines there, which will provide necessary conduct for a new authentication process.\u00a0<\/p>\n<p>Before we continue we need to get base64-encoded credentials for the user <code>kibana<\/code> with password\u00a0<code>$3cuRep@sSW0rd<\/code> which will be used after successful SSO login.\u00a0<\/p>\n<p>Execute the command:<\/p>\n<pre><code>echo -n 'kibana:$3cuRep@sSW0rd' | base64<\/code><\/pre>\n<p>Resulting string:\u00a0<code>a2liYW5hOiQzY3VSZXBAc1NXMHJk<\/code><\/p>\n<p>Now we are ready to bake the config. Modify config for <code>location \/<\/code> as follows:<\/p>\n<pre><code class=\"nginx\">  location \/ {     auth_request \/oauth2\/auth;     error_page 401 = \/oauth2\/sign_in;     auth_request_set $user $upstream_http_x_auth_request_user;     auth_request_set $email $upstream_http_x_auth_request_email;     proxy_set_header X-User $user;     proxy_set_header X-Email $email;     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_pass_header Server;     proxy_connect_timeout 3s;     proxy_read_timeout 10s;     auth_request_set $auth_cookie $upstream_http_set_cookie;     add_header Set-Cookie $auth_cookie;     proxy_set_header Authorization \"Basic a2liYW5hOiQzY3VSZXBAc1NXMHJk\";     proxy_pass http:\/\/localhost:5601;   }<\/code><\/pre>\n<p>We need configuration for <code>\/oauth2<\/code> endpoint as well:<\/p>\n<pre><code class=\"nginx\">  location \/oauth2 {     proxy_pass http:\/\/localhost:1080;     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Scheme $scheme;     proxy_set_header X-Auth-Request-Redirect $request_uri;   }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>You can copy and paste the full listing of the config file, just don&#8217;t forget to change paths to SSL certificate and private key:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"nginx\">server {   listen 443 ssl http2 ;   listen [::]:443 ssl http2 ;   ssl_certificate \/etc\/letsencrypt\/live\/kibana.example.com\/fullchain.pem;   ssl_certificate_key \/etc\/letsencrypt\/live\/kibana.example.com\/privkey.pem;   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   ssl_ecdh_curve secp384r1;   ssl_session_cache shared:SSL:10m;   ssl_session_tickets off;   ssl_stapling on;   ssl_stapling_verify on;   add_header Strict-Transport-Security \"max-age=63072000; includeSubdomains; preload\";   add_header X-Content-Type-Options nosniff;   client_max_body_size 1000M;   proxy_connect_timeout 600;   proxy_send_timeout 600;   proxy_read_timeout 600;   send_timeout 600;    location \/ {     auth_request \/oauth2\/auth;     error_page 401 = \/oauth2\/sign_in;     auth_request_set $user $upstream_http_x_auth_request_user;     auth_request_set $email $upstream_http_x_auth_request_email;     proxy_set_header X-User $user;     proxy_set_header X-Email $email;     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_pass_header Server;     proxy_connect_timeout 3s;     proxy_read_timeout 10s;     auth_request_set $auth_cookie $upstream_http_set_cookie;     add_header Set-Cookie $auth_cookie;     proxy_set_header Authorization \"Basic a2liYW5hOiQzY3VSZXBAc1NXMHJk\";     proxy_pass http:\/\/localhost:5601;   }    location \/oauth2 {     proxy_pass http:\/\/localhost:1080;     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Scheme $scheme;     proxy_set_header X-Auth-Request-Redirect $request_uri;   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>Save the changes and exit the text editor. Check new config for validity:<\/p>\n<pre><code class=\"bash\">nginx -t<\/code><\/pre>\n<p>You should get something like:<\/p>\n<pre><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n<p>Now you&#8217;re ready to restart Nginx:<\/p>\n<pre><code>nginx -s reload<\/code><\/pre>\n<p>Now you can navigate to your Kibana URL and check if everything work as expected.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d09\/98a\/f55\/d0998af55e19b680e7b0f41884366a38.png\" width=\"1024\" height=\"587\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d09\/98a\/f55\/d0998af55e19b680e7b0f41884366a38.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/730426\/\"> https:\/\/habr.com\/ru\/articles\/730426\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>As many times before, I keep writing cheat sheets after the tasks which made me search a lot and glue things together before I found a solution. Long story short, this time I was asked to set up Google SSO for Kibana without switching from a basic license to a paid one. Kibana, by the moment, already had authentication set up and the\u00a0customer wanted to log in there with the use of Google Workspace user accounts. Along with that, the customer wanted to keep user\u00a0account which was\u00a0already there, in Kibana. There was no need for role mapping or other advanced features, just plain SSO and that&#8217;s all. As you probably know Elastic provides SSO feature only on paid license, so I have had no other way to get it working except for using 3rd party software. But first things first, let&#8217;s list the steps we should\u00a0go over:<\/p>\n<ol>\n<li>\n<p>Create credentials for the application in GCP Console<\/p>\n<\/li>\n<li>\n<p>Install and set up oauth2-proxy<\/p>\n<\/li>\n<li>\n<p>Set up Nginx<\/p>\n<\/li>\n<\/ol>\n<p>Now let&#8217;s dig into the details.<\/p>\n<h2>Presumptions<\/h2>\n<blockquote>\n<p>Kibana&#8217;s\u00a0url:\u00a0<a href=\"https:\/\/kibana.example.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com<\/a><\/p>\n<p>Username for logging into Kibana: <strong>kibana<\/strong><\/p>\n<p>Password for user <code>kibana<\/code>: <strong>$3cuRep@sSW0rd<\/strong><\/p>\n<p>Nginx is set up and used for reverse-proxying Kibana<\/p>\n<\/blockquote>\n<h2>Getting credentials for authentication at GCP  <\/h2>\n<p>Navigate to\u00a0<a href=\"https:\/\/console.cloud.google.com\/apis\/credentials\" rel=\"noopener noreferrer nofollow\">https:\/\/console.cloud.google.com\/apis\/credentials<\/a><\/p>\n<details class=\"spoiler\">\n<summary>If you don&#8217;t have any GCP project yet, you should create one<\/summary>\n<div class=\"spoiler__content\">\n<p>You can refer to the documentation on the topic\u00a0<a href=\"https:\/\/cloud.google.com\/resource-manager\/docs\/creating-managing-projects\" rel=\"noopener noreferrer nofollow\">https:\/\/cloud.google.com\/resource-manager\/docs\/creating-managing-projects<\/a><\/p>\n<p>Don&#8217;t forget to add authorized email domains which users will be allowed to log into Kibana. <\/p>\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><\/figure>\n<p>On the next page select <code>Application type<\/code> as Web application, <code>Name<\/code> could be any of your preferences, then put URLs of your Kibana as follows:<\/p>\n<ul>\n<li>\n<p>Base URL of your Kibana for\u00a0<code>Authorized JavaScript origins<\/code>:\u00a0<a href=\"https:\/\/kibana.example.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com<\/a><\/p>\n<\/li>\n<li>\n<p>Route to Kibana&#8217;s oauth2 callbacks for\u00a0<code>Authorized redirect URIs<\/code>: <a href=\"https:\/\/kibana.example.com\/oauth2\/callback\" rel=\"noopener noreferrer nofollow\">https:\/\/kibana.example.com\/oauth2\/callback<\/a><\/p>\n<figure class=\"full-width\"><\/figure>\n<p>Click Create and take a note on the contents of the pop-up window after. Copy and save\u00a0<code>Client\u00a0ID<\/code>\u00a0and\u00a0<code>Client secret<\/code>\u00a0as we will need them a bit later.<\/p>\n<figure class=\"full-width\"><\/figure>\n<\/li>\n<\/ul>\n<h2>Setting up oauth2-proxy<\/h2>\n<p>Since ELK is running in Docker containers on the customer&#8217;s side, I decided to use <strong>oauth2-proxy<\/strong> in the container too. But before we run <strong>oauth2-proxy<\/strong> we need to generate value for\u00a0<code>OAUTH2_PROXY_COOKIE_SECRET<\/code> parameter.<\/p>\n<p>Execute the command:<\/p>\n<pre><code class=\"bash\">python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())'<\/code><\/pre>\n<p>Save the resulting value, for example we will take this one\u00a0<code>HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=<\/code><\/p>\n<p>Now we are good to go. There are a number of ways to configure <strong>oauth2-proxy<\/strong> and I choose to do that over environmental variables. Run the container and pass variables and its values with use of\u00a0<code>-e<\/code>\u00a0parameter:<\/p>\n<pre><code class=\"bash\">docker run -d --name oauth2-proxy -p 1080:1080 -p 1443:1443 \\        -e \"OAUTH2_PROXY_COOKIE_SECRET=HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=\" \\        -e \"OAUTH2_PROXY_PROVIDER=google\" \\        -e \"OAUTH2_PROXY_EMAIL_DOMAINS=*\" \\        -e \"OAUTH2_PROXY_CLIENT_ID=848148116345-nphihtsirct0807h85fen01b69si3s9v.apps.googleusercontent.com\" \\        -e \"OAUTH2_PROXY_CLIENT_SECRET=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\" \\        -e \"OAUTH2_PROXY_HTTP_ADDRESS=0.0.0.0:1080\" \\        -e \"OAUTH2_PROXY_UPSTREAMS=https:\/\/kibana.example.com\" \\        quay.io\/oauth2-proxy\/oauth2-proxy:v7.4.0-amd64<\/code><\/pre>\n<blockquote>\n<p>Don&#8217;t forget to put actual values for <code>secrets<\/code> and <code>Client ID<\/code> you got yourself on previous steps instead of the ones I used for writing the examples!<\/p>\n<\/blockquote>\n<p>Check if container&#8217;s status is Up by executing the command:<\/p>\n<pre><code class=\"bash\">docker ps<\/code><\/pre>\n<p>If you prefer docker compose you can use the following <code>yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">version: \"3.2\" services:   oauth2-proxy:     container_name: oauth2-proxy     image: quay.io\/oauth2-proxy\/oauth2-proxy:v7.4.0-amd64     ports:       - \"1080:1080\"       - \"1443:1443\"     environment:       OAUTH2_PROXY_COOKIE_SECRET: \" HUK59dRK_CDMJkYFdmQUlTllqr_j4UTq__2F-v3WWws=\"       OAUTH2_PROXY_PROVIDER: \"google\"       OAUTH2_PROXY_EMAIL_DOMAINS: \"*\"       OAUTH2_PROXY_CLIENT_ID: \" 848148116345-nphihtsirct0807h85fen01b69si3s9v.apps.googleusercontent.com  \"       OAUTH2_PROXY_CLIENT_SECRET: \" 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  \"       OAUTH2_PROXY_HTTP_ADDRESS: \"0.0.0.0:1080\"       OAUTH2_PROXY_UPSTREAMS: \" https:\/\/kibana.example.com\"<\/code><\/pre>\n<p>As for me, all the parameters are self-explanatory but you can refer to the official docs at any time:\u00a0<a href=\"https:\/\/oauth2-proxy.github.io\/oauth2-proxy\/docs\/configuration\/overview\/\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth2-proxy.github.io\/oauth2-proxy\/docs\/configuration\/overview\/<\/a><\/p>\n<p>Check if newly created container is up and oauth2-proxy is running and returns html on requests:<\/p>\n<pre><code class=\"bash\">curl localhost:1080<\/code><\/pre>\n<p>If you get something like that then we are good to go to the next step:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>You can navigate to\u00a0<a href=\"http:\/\/localhost:1080\/\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:1080<\/a>\u00a0in a browser of your choice as well and check if loaded page looks like that:<\/p>\n<figure class=\"\"><\/figure>\n<h2>Modifying Nginx&#8217;s config<\/h2>\n<p>As we assumed before, we use Nginx as a reverse-proxy for Kibana. It means that a minimal configuration of <code>\/<\/code> location is set up and now it&#8217;s time to add a couple of new lines there, which will provide necessary conduct for a new authentication process.\u00a0<\/p>\n<p>Before we continue we need to get base64-encoded credentials for the user <code>kibana<\/code> with password\u00a0<code>$3cuRep@sSW0rd<\/code> which will be used after successful SSO login.\u00a0<\/p>\n<p>Execute the command:<\/p>\n<pre><code>echo -n 'kibana:$3cuRep@sSW0rd' | base64<\/code><\/pre>\n<p>Resulting string:\u00a0<code>a2liYW5hOiQzY3VSZXBAc1NXMHJk<\/code><\/p>\n<p>Now we are ready to bake the config. Modify config for <code>location \/<\/code> as follows:<\/p>\n<pre><code class=\"nginx\">  location \/ {     auth_request \/oauth2\/auth;     error_page 401 = \/oauth2\/sign_in;     auth_request_set $user $upstream_http_x_auth_request_user;     auth_request_set $email $upstream_http_x_auth_request_email;     proxy_set_header X-User $user;     proxy_set_header X-Email $email;     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_pass_header Server;     proxy_connect_timeout 3s;     proxy_read_timeout 10s;     auth_request_set $auth_cookie $upstream_http_set_cookie;     add_header Set-Cookie $auth_cookie;     proxy_set_header Authorization \"Basic a2liYW5hOiQzY3VSZXBAc1NXMHJk\";     proxy_pass http:\/\/localhost:5601;   }<\/code><\/pre>\n<p>We need configuration for <code>\/oauth2<\/code> endpoint as well:<\/p>\n<pre><code class=\"nginx\">  location \/oauth2 {     proxy_pass http:\/\/localhost:1080;     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Scheme $scheme;     proxy_set_header X-Auth-Request-Redirect $request_uri;   }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>You can copy and paste the full listing of the config file, just don&#8217;t forget to change paths to SSL certificate and private key:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"nginx\">server {   listen 443 ssl http2 ;   listen [::]:443 ssl http2 ;   ssl_certificate \/etc\/letsencrypt\/live\/kibana.example.com\/fullchain.pem;   ssl_certificate_key \/etc\/letsencrypt\/live\/kibana.example.com\/privkey.pem;   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   ssl_ecdh_curve secp384r1;   ssl_session_cache shared:SSL:10m;   ssl_session_tickets off;   ssl_stapling on;   ssl_stapling_verify on;   add_header Strict-Transport-Security \"max-age=63072000; includeSubdomains; preload\";   add_header X-Content-Type-Options nosniff;   client_max_body_size 1000M;   proxy_connect_timeout 600;   proxy_send_timeout 600;   proxy_read_timeout 600;   send_timeout 600;    location \/ {     auth_request \/oauth2\/auth;     error_page 401 = \/oauth2\/sign_in;     auth_request_set $user $upstream_http_x_auth_request_user;     auth_request_set $email $upstream_http_x_auth_request_email;     proxy_set_header X-User $user;     proxy_set_header X-Email $email;     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_pass_header Server;     proxy_connect_timeout 3s;     proxy_read_timeout 10s;     auth_request_set $auth_cookie $upstream_http_set_cookie;     add_header Set-Cookie $auth_cookie;     proxy_set_header Authorization \"Basic a2liYW5hOiQzY3VSZXBAc1NXMHJk\";     proxy_pass http:\/\/localhost:5601;   }    location \/oauth2 {     proxy_pass http:\/\/localhost:1080;     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Scheme $scheme;     proxy_set_header X-Auth-Request-Redirect $request_uri;   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>Save the changes and exit the text editor. Check new config for validity:<\/p>\n<pre><code class=\"bash\">nginx -t<\/code><\/pre>\n<p>You should get something like:<\/p>\n<pre><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n<p>Now you&#8217;re ready to restart Nginx:<\/p>\n<pre><code>nginx -s reload<\/code><\/pre>\n<p>Now you can navigate to your Kibana URL and check if everything work as expected.<\/p>\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/730426\/\"> https:\/\/habr.com\/ru\/articles\/730426\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-397062","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=397062"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397062\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}