0597.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Create and Apply SSL Certificates for Portainer</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Browser Based,Docker Made Easy,Home Lab,Home Lab Ideas,Self-Hosted,Web Based,Web Based Tools,Containerization,Docker,Docker Management,Homelab,Portainer,SSL,PKI,Linux,Homelab Ideas,HTTPS,Certificates,Apply SSL Certificates To Portainer,HTTPS Portainer Web Interface,XCI,Private Key Infrastructure,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Create and Apply SSL Certificates for Portainer">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="05/21/2023 07:18:57 AM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Create and Apply SSL Certificates for Portainer</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>Prerequisites</h2>
  26. <ul>
  27. <li class="noCheckbox">A XCA PKI database <a href="https://youtu.be/ezzj3x207lQ" target="_blank">https://youtu.be/ezzj3x207lQ</a></li>
  28. </ul>
  29. <h2>Create Your SSL Certificate</h2>
  30. <ol>
  31. <li>Launch XCA</li>
  32. <li>Open the PKI database if it is not already (File &gt; Open DataBase), enter password</li>
  33. <li>Click on the Certificates tab, right click on your Intermediate CA certificate</li>
  34. <li>Select New</li>
  35. <li>On the Source tab, make sure Use this Certificate for signing is selected</li>
  36. <li>Verify your Intermediate CA certificate is selected from the drop down</li>
  37. <li>Click the Subject tab</li>
  38. <li>Complete the Distinguished Name section
  39. <p>internalName: ctr.i12bretro.local<br />
  40. countryName: US<br />
  41. stateOrProvinceName: Virginia<br />
  42. localityName: Northern<br />
  43. organizationName: i12bretro<br />
  44. organizationUnitName: i12bretro Certificate Authority<br />
  45. commonName: ctr.i12bretro.local</p>
  46. </li>
  47. <li>Click the Generate a New Key button</li>
  48. <li>Enter a name and set the key size to at least 2048</li>
  49. <li>Click Create</li>
  50. <li>Click on the Extensions tab</li>
  51. <li>Select End Entity from the type list</li>
  52. <li>Click Edit next to Subject Alternative Name</li>
  53. <li>Add any DNS or IP addresses that the certificate will identify</li>
  54. <li>Update the validity dates to fit your needs</li>
  55. <li>Click the Key Usage tab</li>
  56. <li>Under Key Usage select Digital Signature, Key Encipherment</li>
  57. <li>Under Extended Key Usage select Web Server and Web Client Authentication</li>
  58. <li>Click the Netscape tab</li>
  59. <li>Select SSL Server</li>
  60. <li>Click OK to create the certificate</li>
  61. </ol>
  62. <h2>Exporting Required Files</h2>
  63. <ol>
  64. <li>In XCA, click on the Certificates tab</li>
  65. <li>Right click the SSL certificate &gt; Export &gt; File</li>
  66. <li>Set the file name to ssl.crt verify the export format is PEM (*.crt)</li>
  67. <li>Click OK</li>
  68. <li>Click the Private Keys tab</li>
  69. <li>Right click the private key generated for the SSL certificate &gt; Export &gt; File</li>
  70. <li>Set the file name to ssl.key and verify the export format is PEM Private (*.pem)</li>
  71. <li>Click OK</li>
  72. </ol>
  73. <h2>Method 1: Applying SSL Certificates to Portainer Web UI</h2>
  74. <ol>
  75. <li>If the Portainer container wasn&#39;t setup to listen on 9443, connect to the Docker host and run the following commands
  76. <div class="codeBlock"># list running containers to find the name of the portainer container<br />
  77. docker ps<br />
  78. # stop the running portainer container<br />
  79. docker stop portainer<br />
  80. # remove the running portainer container<br />
  81. docker rm portainer --force<br />
  82. # recreate the portainer container with port 9443<br />
  83. # modify as needed<br />
  84. docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v ~/docker/portainer:/data portainer/portainer-ce</div>
  85. </li>
  86. <li>Open a web browser and navigate to http://DNSorIP:9000</li>
  87. <li>Log into Portainer</li>
  88. <li>Click Settings in the left navigation</li>
  89. <li>Scroll to the SSL certificate section</li>
  90. <li>Click Select file under Upload X.509 certificate &gt; Browse to and select the ssl.crt file created earlier</li>
  91. <li>Click Select file under Upload a private key &gt; Browse to and select the ssl.key file created earlier</li>
  92. <li>Click the Apply Changes button</li>
  93. <li>Update the browser URL to https://DNSorIP:9443</li>
  94. <li>Welcome to Portainer running via SSL</li>
  95. </ol>
  96. <h2>Method 2: Applying SSL Certificates to Portainer CLI</h2>
  97. <ol>
  98. <li>Download WinSCP <a href="https://winscp.net/eng/downloads.php" target="_blank">Download</a></li>
  99. <li>Extract WinSCP and run the executable</li>
  100. <li>Connect to the Portainer host IP address via WinSCP</li>
  101. <li>Copy the exported .pem files to the Portainer host</li>
  102. <li>Connect to the Docker host and run the following commands
  103. <div class="codeBlock"># list running containers to find the name of the portainer container<br />
  104. docker ps<br />
  105. # stop the running portainer container<br />
  106. docker stop portainer<br />
  107. # remove the running portainer container<br />
  108. docker rm portainer --force<br />
  109. # recreate the portainer container with ssl enabled<br />
  110. # modify as needed<br />
  111. docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v ~/docker/portainer:/data portainer/portainer-ce --ssl --sslcert /data/ssl.crt --sslkey /data/ssl.key</div>
  112. </li>
  113. <li>Open a web browser and navigate to https://DNSorIP:9443</li>
  114. <li>Welcome to Portainer running via SSL</li>
  115. </ol>
  116. <p>Further Reading: <a href="https://documentation.portainer.io/v2.0/deploy/ssl/" target="_blank">https://documentation.portainer.io/v2.0/deploy/ssl/</a></p> </div>
  117. </div>
  118. </body>
  119. </html>