web-dev-qa-db-ja.com

Keyframeのログインページをiframeに設定するにはどうすればよいですか?

ローカルで実行されているWebサーバーがあり、iframe内に(別のドメインの)Keycloakログインページを配置したいと考えています。 Keycloak Real Settings> Security Defenses> Headers> Content-Security-Policyで次の設定を試しました

frame-src 'self' http://127.0.0.1 http://192.168.1.140 http://localhost *.home-life.hub http://trex-macbook.home-life.hub localhost; frame-ancestors 'self'; object-src 'none';

基本的に、ローカルIPアドレスとホスト名をソースとしてframe-src

ログインページが表示されず、ブラウザコンソールでこのエラーが発生する

Refused to display 'http://keycloak.example.com:8080/auth/realms/master/protocol/openid-connect/auth?client_id=es-openid&response_type=code&redirect_uri=https%3A%2F%2Fkibana.example.com%3A5601%2Fauth%2Fopenid%2Flogin&state=3RV-_nbW-RvmB8EfUwgkJq&scope=profile%20email%20openid' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

私のカスタムヘッダーは存在します enter image description here

私のサーバーとUI(サーバーレンダリング)コード:

'use strict';

const Hapi = require('@hapi/hapi');

const init = async () => {
  // Run server on all interfaces
  const server = Hapi.server({
    port: 3000,
  });

  await server.start();

  // server.ext('onPreResponse', (req, h) => {
  //   req.response.header('Content-Security-Policy', "default-src 'self' *.example.com");
  //   console.log('req.response.headers', req.response.headers);
  //   return h.continue;
  // });

  server.route({
    method: 'GET',
    path: '/home',
    handler: () => {
      return `<html>
                <head>
                  <title>searchguard kibana openid keycloak</title>
                </head>
                <body>
                  <p>
                    <iframe src="https://kibana.example.com:5601" width="800" height="600"></iframe>
                  </p>
                </body>
              </html>`;
    },
  });

  server.route({
    method: '*',
    path: '/{path*}',
    handler: (req, h) => {
      return h.redirect('/home');
    },
  });

  console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {
  console.log(err);
  process.exit(1);
});

init();

Iframeは最後にkibana.example.comのページを表示します。 Keycloakは、kibana.example.comのIDプロバイダーとして使用されます。

2
srgbnd

変更してみてください:

frame-ancestors 'self';

frame-ancestors 'self' http://127.0.0.1 http://192.168.1.140 http://localhost *.home-life.hub http://trex-macbook.home-life.hub localhost;

一般に、Tweakフレーム祖先CSP構成。

3
Jan Garaj