You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

407 lines
15 KiB

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  5. <head>
  6. <!-- 2023-04-20 Thu 22:23 -->
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <title>Lab 11 Solution Amirlan Sharipov (BS21-CS-01)</title>
  10. <meta name="author" content="Amirlan Sharipov (BS21-CS-01)" />
  11. <meta name="generator" content="Org Mode" />
  12. <style>
  13. #content { max-width: 60em; margin: auto; }
  14. .title { text-align: center;
  15. margin-bottom: .2em; }
  16. .subtitle { text-align: center;
  17. font-size: medium;
  18. font-weight: bold;
  19. margin-top:0; }
  20. .todo { font-family: monospace; color: red; }
  21. .done { font-family: monospace; color: green; }
  22. .priority { font-family: monospace; color: orange; }
  23. .tag { background-color: #eee; font-family: monospace;
  24. padding: 2px; font-size: 80%; font-weight: normal; }
  25. .timestamp { color: #bebebe; }
  26. .timestamp-kwd { color: #5f9ea0; }
  27. .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
  28. .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
  29. .org-center { margin-left: auto; margin-right: auto; text-align: center; }
  30. .underline { text-decoration: underline; }
  31. #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  32. p.verse { margin-left: 3%; }
  33. pre {
  34. border: 1px solid #e6e6e6;
  35. border-radius: 3px;
  36. background-color: #f2f2f2;
  37. padding: 8pt;
  38. font-family: monospace;
  39. overflow: auto;
  40. margin: 1.2em;
  41. }
  42. pre.src {
  43. position: relative;
  44. overflow: auto;
  45. }
  46. pre.src:before {
  47. display: none;
  48. position: absolute;
  49. top: -8px;
  50. right: 12px;
  51. padding: 3px;
  52. color: #555;
  53. background-color: #f2f2f299;
  54. }
  55. pre.src:hover:before { display: inline; margin-top: 14px;}
  56. /* Languages per Org manual */
  57. pre.src-asymptote:before { content: 'Asymptote'; }
  58. pre.src-awk:before { content: 'Awk'; }
  59. pre.src-authinfo::before { content: 'Authinfo'; }
  60. pre.src-C:before { content: 'C'; }
  61. /* pre.src-C++ doesn't work in CSS */
  62. pre.src-clojure:before { content: 'Clojure'; }
  63. pre.src-css:before { content: 'CSS'; }
  64. pre.src-D:before { content: 'D'; }
  65. pre.src-ditaa:before { content: 'ditaa'; }
  66. pre.src-dot:before { content: 'Graphviz'; }
  67. pre.src-calc:before { content: 'Emacs Calc'; }
  68. pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  69. pre.src-fortran:before { content: 'Fortran'; }
  70. pre.src-gnuplot:before { content: 'gnuplot'; }
  71. pre.src-haskell:before { content: 'Haskell'; }
  72. pre.src-hledger:before { content: 'hledger'; }
  73. pre.src-java:before { content: 'Java'; }
  74. pre.src-js:before { content: 'Javascript'; }
  75. pre.src-latex:before { content: 'LaTeX'; }
  76. pre.src-ledger:before { content: 'Ledger'; }
  77. pre.src-lisp:before { content: 'Lisp'; }
  78. pre.src-lilypond:before { content: 'Lilypond'; }
  79. pre.src-lua:before { content: 'Lua'; }
  80. pre.src-matlab:before { content: 'MATLAB'; }
  81. pre.src-mscgen:before { content: 'Mscgen'; }
  82. pre.src-ocaml:before { content: 'Objective Caml'; }
  83. pre.src-octave:before { content: 'Octave'; }
  84. pre.src-org:before { content: 'Org mode'; }
  85. pre.src-oz:before { content: 'OZ'; }
  86. pre.src-plantuml:before { content: 'Plantuml'; }
  87. pre.src-processing:before { content: 'Processing.js'; }
  88. pre.src-python:before { content: 'Python'; }
  89. pre.src-R:before { content: 'R'; }
  90. pre.src-ruby:before { content: 'Ruby'; }
  91. pre.src-sass:before { content: 'Sass'; }
  92. pre.src-scheme:before { content: 'Scheme'; }
  93. pre.src-screen:before { content: 'Gnu Screen'; }
  94. pre.src-sed:before { content: 'Sed'; }
  95. pre.src-sh:before { content: 'shell'; }
  96. pre.src-sql:before { content: 'SQL'; }
  97. pre.src-sqlite:before { content: 'SQLite'; }
  98. /* additional languages in org.el's org-babel-load-languages alist */
  99. pre.src-forth:before { content: 'Forth'; }
  100. pre.src-io:before { content: 'IO'; }
  101. pre.src-J:before { content: 'J'; }
  102. pre.src-makefile:before { content: 'Makefile'; }
  103. pre.src-maxima:before { content: 'Maxima'; }
  104. pre.src-perl:before { content: 'Perl'; }
  105. pre.src-picolisp:before { content: 'Pico Lisp'; }
  106. pre.src-scala:before { content: 'Scala'; }
  107. pre.src-shell:before { content: 'Shell Script'; }
  108. pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
  109. /* additional language identifiers per "defun org-babel-execute"
  110. in ob-*.el */
  111. pre.src-cpp:before { content: 'C++'; }
  112. pre.src-abc:before { content: 'ABC'; }
  113. pre.src-coq:before { content: 'Coq'; }
  114. pre.src-groovy:before { content: 'Groovy'; }
  115. /* additional language identifiers from org-babel-shell-names in
  116. ob-shell.el: ob-shell is the only babel language using a lambda to put
  117. the execution function name together. */
  118. pre.src-bash:before { content: 'bash'; }
  119. pre.src-csh:before { content: 'csh'; }
  120. pre.src-ash:before { content: 'ash'; }
  121. pre.src-dash:before { content: 'dash'; }
  122. pre.src-ksh:before { content: 'ksh'; }
  123. pre.src-mksh:before { content: 'mksh'; }
  124. pre.src-posh:before { content: 'posh'; }
  125. /* Additional Emacs modes also supported by the LaTeX listings package */
  126. pre.src-ada:before { content: 'Ada'; }
  127. pre.src-asm:before { content: 'Assembler'; }
  128. pre.src-caml:before { content: 'Caml'; }
  129. pre.src-delphi:before { content: 'Delphi'; }
  130. pre.src-html:before { content: 'HTML'; }
  131. pre.src-idl:before { content: 'IDL'; }
  132. pre.src-mercury:before { content: 'Mercury'; }
  133. pre.src-metapost:before { content: 'MetaPost'; }
  134. pre.src-modula-2:before { content: 'Modula-2'; }
  135. pre.src-pascal:before { content: 'Pascal'; }
  136. pre.src-ps:before { content: 'PostScript'; }
  137. pre.src-prolog:before { content: 'Prolog'; }
  138. pre.src-simula:before { content: 'Simula'; }
  139. pre.src-tcl:before { content: 'tcl'; }
  140. pre.src-tex:before { content: 'TeX'; }
  141. pre.src-plain-tex:before { content: 'Plain TeX'; }
  142. pre.src-verilog:before { content: 'Verilog'; }
  143. pre.src-vhdl:before { content: 'VHDL'; }
  144. pre.src-xml:before { content: 'XML'; }
  145. pre.src-nxml:before { content: 'XML'; }
  146. /* add a generic configuration mode; LaTeX export needs an additional
  147. (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
  148. pre.src-conf:before { content: 'Configuration File'; }
  149. table { border-collapse:collapse; }
  150. caption.t-above { caption-side: top; }
  151. caption.t-bottom { caption-side: bottom; }
  152. td, th { vertical-align:top; }
  153. th.org-right { text-align: center; }
  154. th.org-left { text-align: center; }
  155. th.org-center { text-align: center; }
  156. td.org-right { text-align: right; }
  157. td.org-left { text-align: left; }
  158. td.org-center { text-align: center; }
  159. dt { font-weight: bold; }
  160. .footpara { display: inline; }
  161. .footdef { margin-bottom: 1em; }
  162. .figure { padding: 1em; }
  163. .figure p { text-align: center; }
  164. .equation-container {
  165. display: table;
  166. text-align: center;
  167. width: 100%;
  168. }
  169. .equation {
  170. vertical-align: middle;
  171. }
  172. .equation-label {
  173. display: table-cell;
  174. text-align: right;
  175. vertical-align: middle;
  176. }
  177. .inlinetask {
  178. padding: 10px;
  179. border: 2px solid gray;
  180. margin: 10px;
  181. background: #ffffcc;
  182. }
  183. #org-div-home-and-up
  184. { text-align: right; font-size: 70%; white-space: nowrap; }
  185. textarea { overflow-x: auto; }
  186. .linenr { font-size: smaller }
  187. .code-highlighted { background-color: #ffff00; }
  188. .org-info-js_info-navigation { border-style: none; }
  189. #org-info-js_console-label
  190. { font-size: 10px; font-weight: bold; white-space: nowrap; }
  191. .org-info-js_search-highlight
  192. { background-color: #ffff00; color: #000000; font-weight: bold; }
  193. .org-svg { }
  194. </style>
  195. </head>
  196. <body>
  197. <div id="content" class="content">
  198. <h1 class="title">Lab 11 Solution Amirlan Sharipov (BS21-CS-01)</h1>
  199. <div id="table-of-contents" role="doc-toc">
  200. <h2>Table of Contents</h2>
  201. <div id="text-table-of-contents" role="doc-toc">
  202. <ul>
  203. <li><a href="#orgb5383c0">1. Question 1</a></li>
  204. <li><a href="#org68c7989">2. Question 2</a>
  205. <ul>
  206. <li><a href="#orga0d213f">2.1. Choose a host OS that provides maximum container isolation. (hardened host OS)</a></li>
  207. <li><a href="#org68baa0a">2.2. Use network namespaces</a></li>
  208. <li><a href="#org5ffdd26">2.3. Use kubernetes to manage access right</a></li>
  209. <li><a href="#org7a83b2b">2.4. Monitor the logs using SIEM tools</a></li>
  210. <li><a href="#orgc61de8d">2.5. Don&rsquo;t use outdated images</a></li>
  211. </ul>
  212. </li>
  213. <li><a href="#orgf0252b1">3. Question 3</a></li>
  214. <li><a href="#orgad34306">4. Question 4</a></li>
  215. <li><a href="#org10585ce">5. Question 5</a></li>
  216. <li><a href="#org2339204">6. Question 6</a></li>
  217. <li><a href="#org5da35ee">7. Question 8</a></li>
  218. </ul>
  219. </div>
  220. </div>
  221. <div id="outline-container-orgb5383c0" class="outline-2">
  222. <h2 id="orgb5383c0"><span class="section-number-2">1.</span> Question 1</h2>
  223. <div class="outline-text-2" id="text-1">
  224. <p>
  225. Source: <a href="https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile">https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile</a>
  226. Usually, the entrypoint is /bin/sh -c CMD. So this command gets executed when the container is run.
  227. It&rsquo;s a standard practice to customize CMD, though. If you want to use other shell for executing commands, it may be useful to customize the entrypoint.
  228. </p>
  229. </div>
  230. </div>
  231. <div id="outline-container-org68c7989" class="outline-2">
  232. <h2 id="org68c7989"><span class="section-number-2">2.</span> Question 2</h2>
  233. <div class="outline-text-2" id="text-2">
  234. <p>
  235. Source: <a href="https://www.redhat.com/en/topics/security/container-security">https://www.redhat.com/en/topics/security/container-security</a>
  236. </p>
  237. </div>
  238. <div id="outline-container-orga0d213f" class="outline-3">
  239. <h3 id="orga0d213f"><span class="section-number-3">2.1.</span> Choose a host OS that provides maximum container isolation. (hardened host OS)</h3>
  240. </div>
  241. <div id="outline-container-org68baa0a" class="outline-3">
  242. <h3 id="org68baa0a"><span class="section-number-3">2.2.</span> Use network namespaces</h3>
  243. </div>
  244. <div id="outline-container-org5ffdd26" class="outline-3">
  245. <h3 id="org5ffdd26"><span class="section-number-3">2.3.</span> Use kubernetes to manage access right</h3>
  246. </div>
  247. <div id="outline-container-org7a83b2b" class="outline-3">
  248. <h3 id="org7a83b2b"><span class="section-number-3">2.4.</span> Monitor the logs using SIEM tools</h3>
  249. </div>
  250. <div id="outline-container-orgc61de8d" class="outline-3">
  251. <h3 id="orgc61de8d"><span class="section-number-3">2.5.</span> Don&rsquo;t use outdated images</h3>
  252. </div>
  253. </div>
  254. <div id="outline-container-orgf0252b1" class="outline-2">
  255. <h2 id="orgf0252b1"><span class="section-number-2">3.</span> Question 3</h2>
  256. <div class="outline-text-2" id="text-3">
  257. <p>
  258. <img src="./container-ls-1.jpg" alt="container-ls-1.jpg" />
  259. <img src="./container-ls-2.jpg" alt="container-ls-2.jpg" />
  260. </p>
  261. </div>
  262. </div>
  263. <div id="outline-container-orgad34306" class="outline-2">
  264. <h2 id="orgad34306"><span class="section-number-2">4.</span> Question 4</h2>
  265. <div class="outline-text-2" id="text-4">
  266. <p>
  267. Source: <a href="https://docs.docker.com/engine/reference/commandline/cp/">https://docs.docker.com/engine/reference/commandline/cp/</a>
  268. docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
  269. </p>
  270. <p>
  271. Example:
  272. </p>
  273. <div class="org-src-container">
  274. <pre class="src src-bash"><span style="color: #c792ea;">cat</span> ~/nginx.sh
  275. </pre>
  276. </div>
  277. <pre class="example" id="orgb1f78fc">
  278. #!/bin/bash
  279. docker run \
  280. -v /etc/ssl/certs/monica.crt:/etc/ssl/certs/monica.crt \
  281. -v /etc/ssl/private/monica.key:/etc/ssl/private/monica.key \
  282. -v /home/rinri/.config/nginx:/etc/nginx/conf.d \
  283. -v /home/rinri/edu/sna/:/var/www \
  284. -p 80:80 -p 443:443 -p 5000:5000 \
  285. --restart unless-stopped \
  286. -d nginx
  287. </pre>
  288. <p>
  289. After running nginx.sh:
  290. <img src="./container-cp.jpg" alt="container-cp.jpg" />
  291. </p>
  292. </div>
  293. </div>
  294. <div id="outline-container-org10585ce" class="outline-2">
  295. <h2 id="org10585ce"><span class="section-number-2">5.</span> Question 5</h2>
  296. <div class="outline-text-2" id="text-5">
  297. <div class="org-src-container">
  298. <pre class="src src-bash"><span style="color: #c792ea;">echo</span> <span style="color: #c3e88d;">"Run Nginx container:"</span>
  299. <span style="color: #c792ea;">cat</span> ~/nginx.sh
  300. <span style="color: #c792ea;">echo</span> <span style="color: #c3e88d;">"Config file:"</span>
  301. <span style="color: #c792ea;">cat</span> ~/.config/nginx/test.conf
  302. </pre>
  303. </div>
  304. <pre class="example" id="org01c388f">
  305. Run Nginx container:
  306. #!/bin/bash
  307. docker run \
  308. -v /etc/ssl/certs/monica.crt:/etc/ssl/certs/monica.crt \
  309. -v /etc/ssl/private/monica.key:/etc/ssl/private/monica.key \
  310. -v /home/rinri/.config/nginx:/etc/nginx/conf.d \
  311. -v /home/rinri/edu/sna/:/var/www \
  312. -p 80:80 -p 443:443 -p 5000:5000 \
  313. --restart unless-stopped \
  314. -d nginx
  315. Config file:
  316. server {
  317. listen 5000;
  318. listen [::]:5000;
  319. root /var/www;
  320. index index.html index.htm;
  321. location / {
  322. try_files $uri $uri/ =404;
  323. }
  324. }
  325. server {
  326. listen 80;
  327. listen [::]:80;
  328. server_name monica.local;
  329. return 302 https://$server_name$request_uri;
  330. }
  331. server {
  332. listen 443;
  333. listen [::]:443;
  334. include conf.d/snippets/self-signed.conf;
  335. server_name monica.local;
  336. location / {
  337. proxy_pass http://172.17.0.4;
  338. proxy_set_header Host monica.local;
  339. }
  340. }
  341. </pre>
  342. </div>
  343. </div>
  344. <div id="outline-container-org2339204" class="outline-2">
  345. <h2 id="org2339204"><span class="section-number-2">6.</span> Question 6</h2>
  346. <div class="outline-text-2" id="text-6">
  347. <p>
  348. In /etc/rsyslog.conf:
  349. $ModLoad imtcp.so
  350. $InputTCPServerRun 514
  351. </p>
  352. <p>
  353. Command:
  354. docker run -it &#x2013;log-driver syslog &#x2013;log-opt syslog-address=tcp://172.17.0.1:514 alpine ash
  355. </p>
  356. </div>
  357. </div>
  358. <div id="outline-container-org5da35ee" class="outline-2">
  359. <h2 id="org5da35ee"><span class="section-number-2">7.</span> Question 8</h2>
  360. <div class="outline-text-2" id="text-7">
  361. <p>
  362. FROM alpine
  363. RUN apk add &#x2013;update &#x2013;no-cache python3 &amp;&amp; ln -sf python3 /usr/bin/python
  364. RUN python3 -m ensurepip
  365. RUN pip3 install &#x2013;no-cache &#x2013;upgrade pip setuptools
  366. RUN touch index.html
  367. RUN echo &ldquo;&lt;html&gt;&lt;h1&gt;Testing web&lt;/h1&gt;&lt;/html&gt;&rdquo; &gt;&gt; index.html
  368. CMD [&ldquo;python&rdquo;, &ldquo;-m&rdquo;, &ldquo;http.server&rdquo;]
  369. </p>
  370. <p>
  371. changed apt to apk.
  372. source: <a href="https://stackoverflow.com/questions/62554991/how-do-i-install-python-on-alpine-linux">https://stackoverflow.com/questions/62554991/how-do-i-install-python-on-alpine-linux</a>
  373. </p>
  374. </div>
  375. </div>
  376. </div>
  377. <div id="postamble" class="status">
  378. <p class="author">Author: Amirlan Sharipov (BS21-CS-01)</p>
  379. <p class="date">Created: 2023-04-20 Thu 22:23</p>
  380. </div>
  381. </body>
  382. </html>