2017-05-15 8 views
1

いくつかの情報をデータベースに保存するために使用できるいくつかのREST APIを公開しているAzureにドッカーイメージを展開しています。
質問:HTTPの代わりにHTTPSを強制し、自己署名証明書を使用することは可能ですか?AzureでのHTTPS RESTAPI

私のREST APIは、このようなものであればそう:

curl -i -H "Content-type: application/json" http://AZURE_IP_ADDRESS:5100/module/api/v1.0/person -X POST -d '{ "name" : "test", "surname": "test_surname" }' 

私は、証明書のマシンが前のコマンドを実行できることをしたいです。

私が理解している限り、AzureはTruster CAの証明書登録で動作しますが、すべてを行う前にいくつかのテストを行いたいと思います。

いくつかの言葉では、私がHTTPS要求を行っているマシンが要求を実行するために「許可」されている場合にのみ、REST APIを呼び出す必要があります。
私は少し混乱しています。 Azureで動作するドッカーが提供するREST APIを保護する方法を知りたいのですが、Azureの機能を使用しないという点でより一般的なものになりたいと思います。アズール。手順の下に、次のことで

# Create the CA Key and Certificate for signing Client Certs 
openssl genrsa -des3 -out ca.key 4096 
openssl req -new -x509 -days 365 -key ca.key -out ca.crt 

# Create the Server Key, CSR, and Certificate 
openssl genrsa -des3 -out server.key 1024 
openssl req -new -key server.key -out server.csr 

# We're self signing our own server cert here. This is a no-no in production. 
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt 

# Create the Client Key and CSR 
openssl genrsa -des3 -out client.key 1024 
openssl req -new -key client.key -out client.csr 

# Sign the client certificate with our CA cert. Unlike signing our own server cert, this is what we want to do. 
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt 



openssl rsa -in server.key -out server_without_key.key  

と次のようにnginx.conf設定:

server { 
     listen 443 ssl; 


     ssl_certificate  /etc/nginx/certs/server.crt; 
     ssl_certificate_key /etc/nginx/certs/server_without_key.key; 
     ssl_client_certificate /etc/nginx/certs/ca.crt; # the cert used to sign the client certificates 
     ssl_verify_client  on; # force SSL verification (can also be set to 'optional') 


     ssl  on; 
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
     ssl_prefer_server_ciphers on; 
     add_header Strict-Transport-Security "max-age=31536000; includeSubDomains"; 
     ssl_session_cache shared:SSL:10m; 
     ssl_session_timeout 10m; 
     keepalive_timeout 70; 

    } 

私はカールたら:

curl -v -s -k --key client.key --cert client.crt https://172.18.0.9 

(dir`でいるクライアント。キーと* crtが格納されています)次の出力があります

* Rebuilt URL to: https://172.18.0.9/ 
* Trying 172.18.0.9... 
* Connected to 172.18.0.9 (172.18.0.9) port 443 (#0) 
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt 
* found 698 certificates in /etc/ssl/certs 
* ALPN, offering http/1.1 
* error reading X.509 key or certificate file: Error while reading file. 
* Closing connection 0 

ご提案がありますか?出来ますか?あなたはあなたの正確な構成の詳細を使用しているWebサーバによっては感謝

答えて

2

が異なります

が、一言で言えば何がやりたいことは、HTTPSへのすべてのHTTP要求をリダイレクトしています。いくつかのリンクについては以下を参照してください。

クライアント側では、リダイレクトに従う必要があります。通常、ブラウザは自動的にそれを行うように設定されています。 curlを使用すると、これは-Lフラグによって実行されます。

curl -L -i -H "Content-type: application/json" http://AZURE_IP_ADDRESS:5100/module/api/v1.0/person -X POST -d '{ "name" : "test", "surname": "test_surname" }' 

これらは、サーバー側で役立つ説明です。 nginxの https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom

アパッチ https://wiki.apache.org/httpd/RedirectSSL

は本当にAPIのためにあまり意味がありませんリダイレクト https://www.iis.net/configreference/system.webserver/httpredirect

+0

注IIS。クライアントライブラリによっては、それらが後に続くかどうかは関係ありません。正直言って、これはサポートされていないという返事を返すだけで、HTTPを完全に無効にすることさえできます。APIでは、ブラウザにドメイン名を入力してデフォルトでHTTPに行くという問題はありません。開発者は、APIを使用してすぐにHTTPSを使用するように設定できます。 HTTPを試してもエラーになると、アクセスにHTTPS URLを使用する必要があることがわかります。 – juunas

+0

APIクライアントアプリケーションの開発者は、HTTPステータスコード301の意味を理解する必要があるため、リダイレクトは正しいです。あなたは応答を示唆しているようにボディを追加することができますが、それはWebサーバーの設定だけを使用して達成するのは簡単ではないかもしれません。 –

関連する問題