rest - Azure REST API 上的 HTTPS

标签 rest api azure ssl certificate

我正在 Azure 上部署一个 docker 镜像,该镜像正在发布一些 REST API,我可以使用它在数据库中存储一些信息。
问题是:是否可以强制使用 HTTPS 而不是 HTTP 并使用自签名证书?

所以如果我的其余 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 上运行的 docker 提供的 REST API。但我想更通用一些。不只使用 Azure 功能,并在我使用其他功能时做好准备。 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 :

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

(在存储 client.key 和 *crt 的 dir` 中)我有以下输出

* 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 服务器,您的具体配置详细信息会有所不同,但简而言之,您想要做的是将所有 http 请求重定向到 https。请参阅下面的一些链接。

在客户端,要实现此功能,您需要遵循重定向。通常,浏览器被配置为自动执行此操作。使用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

Apache https://wiki.apache.org/httpd/RedirectSSL

IIS https://www.iis.net/configreference/system.webserver/httpredirect

关于rest - Azure REST API 上的 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983862/

相关文章:

javascript - 领英 API : Get Groups I am a Member Of

api - Office365 Sharepoint API 对于联合域失败

azure - ADF CI 构建错误 : Command failed: node/home/shaadmin/myagent/_work/5/s/adf/build/downloads/main. js 验证

java - Azure根据请求id获取操作状态java sdk

javascript - 使用纯 Javascript 页面访问force.com REST API

java - 如何在 jax-rs Restful web 服务中获取 Json 对象

.net - IIS API-创建虚拟目录?

Azure API 管理 - 如何使用 Azure CLI 设置 VNET/子网?

python - 如何从 Flask 中的 HTTP 删除访问正文?

rest - Swagger UI : How to custom sort resources