<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Victor-Laurențiu Stănescu on Medium]]></title>
        <description><![CDATA[Stories by Victor-Laurențiu Stănescu on Medium]]></description>
        <link>https://medium.com/@vtstanescu?source=rss-71a4cf2f5337------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AIJY2GpCcUI_37s-8ajaFg@2x.jpeg</url>
            <title>Stories by Victor-Laurențiu Stănescu on Medium</title>
            <link>https://medium.com/@vtstanescu?source=rss-71a4cf2f5337------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:25:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vtstanescu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[“SSH” Alternative in AWS]]></title>
            <link>https://medium.com/@vtstanescu/ssh-alternative-in-aws-d0f67a5a460d?source=rss-71a4cf2f5337------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0f67a5a460d</guid>
            <category><![CDATA[sms]]></category>
            <category><![CDATA[ssm-agent]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[session-manager]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Victor-Laurențiu Stănescu]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 11:58:20 GMT</pubDate>
            <atom:updated>2022-11-04T11:58:20.359Z</atom:updated>
            <content:encoded><![CDATA[<p>Keep your instances private and still be able to manage them.</p><figure><img alt="AWS Systems Manager Session Manager Architecture diagram" src="https://cdn-images-1.medium.com/max/915/1*85_UEVY1JuMEsIL-W_OjEg.png" /><figcaption>Architectural diagram made by the author</figcaption></figure><p>One of the things I see a lot, from companies using AWS, or devs playing with it, to tutorials and documentation, is the creation of public EC2 instances (with IP addresses reachable from the Internet) for the sole purpose of managing them. I’m mainly talking about SSH, but other protocols like RDP are in the same boat.</p><p>Yes, some do the sane thing of using proper security group rules to narrow done the allowed traffic to their instances, but you still need to manage users on the instance and SSH keys. You’d say there are ways to work around that too, like configuring instances with Ansible and using LDAP for connecting users to solutions like Microsoft Active Directory.</p><h4>But! What if there’s an easier way?</h4><p>That’s where the Session Manager capability of AWS Systems Manager comes in. It is good enough for big enterprises, and exceptional for small companies, or playground environments, where you don’t want to deal with some of the things I’ve mentioned above. You don’t even need a private connection to the AWS network, like a VPN <a href="https://aws.amazon.com/directconnect/">or any other direct link</a>.</p><h4>What does it do?</h4><p>In a nutshell, it allows you to connect to instances (those not reachable from the Internet too) using your AWS session via AWS Management Console (ie. web browser) or AWS CLI.</p><p>It is integrated with AWS Identity &amp; Access Management (IAM) service, so you can decide who has access to which instance, and using SSM documents you can also restrict the commands they use (<em>more on this later</em>). This of course comes with an audit of session activity in AWS CloudTrail.</p><p>It also supports logging the commands executed on each session so you can audit who did what. It can log to an Amazon CloudWatch log group or Amazon S3 bucket.</p><h4>How does it work?</h4><p>As shown in the diagram from the beginning of the article, it leverages the SSM agent installed on the instance, which nowadays comes with most AWS-owned AMIs. The agent connects to the Systems Manager service (<a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-privatelink.html">you can make that connection private too by using AWS Private Link</a>) and that connection is the “private” tunnel between you (outside the AWS network) and your instance (inside the AWS network).</p><h3>Mentions and caveats</h3><ul><li>It is very easy to set this up in its most basic configuration**, so I encourage even new users of AWS to use it and avoid making EC2 instances public unless absolutely necessary*<br><em>* you rarely need an EC2 instance public, depending on your requirements you probably want a load balancer in front of it<br>** all you need is to use an AMI that has an SSM agent already installed***;<br>create your EC2 instance using that AMI;<br>in the instance’s security group only 443 TCP (HTTPS) outbound is required;<br>associate AmazonSSMRoleForInstancesQuickSetup IAM instance profile to the instance (AWS creates this IAM role in your account)<br>*** popular AMIs with SSM agent already installed: amzn2-ami-hvm-2.0* and ubuntu/images/*</em></li><li>EC2 instances must have an IAM instance profile associated.<br>The IAM role gives permission to the EC2 instances, and as such to the SSM agent running on it, to connect to Systems Manager services and to CloudWatch or S3 for sending the logs (and to KMS service too if you enable encryption).<br>AWS provides an IAM policy for the basic requirements (connecting to Systems Manager services), called <em>AmazonSSMManagedInstanceCore.</em><strong><em><br></em></strong>They also create an IAM role (and an IAM instance profile for it) so it is very fast to bootstrap this setup. The role is <em>AmazonSSMRoleForInstancesQuickSetup</em>.</li><li>Session Manager can be used to get an interactive session into the instances (shell or PowerShell console), but it can also be used just to tunnel other protocols like SSH &amp; RDP.<br>Doing that comes with some downsides:<br>1. You lose logging capability since protocols like SSH encrypt all data sent in the session that Session Manager just tunnels at this point.<br>2. You get back to managing users and SSH keys.</li><li>Using SSM documents to limit commands used in the sessions works by enforcing IAM identities (your users) to be able to start sessions while only using the SSM documents you create &amp; manage (in which you specify what commands they can run in the interactive sessions).<br>The last 2 words point out a limitation too: if you just use Session Manager to tunnel other protocols, you cannot rely on SSM documents &amp; IAM policies to make enforcements on what users can do once inside the instance.</li><li><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html">Amazon ECS Exec</a> is also implemented with AWS Systems Manager Session Manager. This is a feature of the Elastic Container Service to help debug running containers by running commands inside them.</li></ul><p>If you want to get in-depth with Session Manager, check out <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html">AWS documentation</a>.</p><p>Feel free to reach out to me if you want to discuss possible setups using Session Manager. Or other AWS services for that matter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0f67a5a460d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Amazon MSK Tips & Quirks]]></title>
            <link>https://blog.devgenius.io/amazon-msk-tips-quirks-7b1e56d53296?source=rss-71a4cf2f5337------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b1e56d53296</guid>
            <category><![CDATA[data-streaming]]></category>
            <category><![CDATA[msk]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[amazon-msk]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Victor-Laurențiu Stănescu]]></dc:creator>
            <pubDate>Sun, 16 Oct 2022 10:47:38 GMT</pubDate>
            <atom:updated>2024-05-08T11:36:22.591Z</atom:updated>
            <content:encoded><![CDATA[<p>Not an introduction to Kafka per-se.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*bIZHvfYDi96pcxRZTPTzow.png" /><figcaption>Diagram made by the author with draw.io</figcaption></figure><p>Once in a while, I will be writing about interesting things I encounter in my day-to-day as a DevOps engineer &amp; solutions architect.</p><p>Recently, I have been developing a solution for loading streaming data into a data warehouse. As most of the time, there are more solutions for one challenge, for this one in particular I was looking at a combination of Kinesis Firehose &amp; S3 or Apache Kafka (Amazon MSK to be precise), a SaaS vs PaaS (although Amazon MSK has a serverless option too).</p><p>Long story short, for the use case I had on my hands it made more sense to use Kafka, alongside Kafka Connect sink connectors to do the job.</p><p>In this post, I will cover some of the quirks, and some tips, I have encountered while implementing this in AWS.</p><h4>1. Client Authentication</h4><p>Amazon MSK provides 4 client authentication methods:</p><ol><li>unauthenticated — please don’t</li><li><a href="https://en.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer">SASL</a> with <a href="https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism">SCRAM</a> — basically username &amp; password with a secret in AWS Secrets Manager for each user</li><li>SASL with AWS IAM — works with IAM identities with policies allowing actions kafka-cluster:*. Similar access control to Kafka ACLs, at cluster/topic/consumer group/transaction levels.</li><li>TLS client certificates — require a private certificate authority (CA) in Amazon Certificate Manager (ACM). This is a pricier authentication method since a private CA in ACM starts at $400/month for the CA and also you pay for the number of certificates issued by the CA</li></ol><p>Out of this list, it’s clear the preferred methods are those involving SASL. Amazon, as always, integrated this into their cloud and added support for IAM. Kafka ACLs do not apply for IAM authenticated clients, so you can leave the Kafka property allow.everyone.if.no.acl.found set to false.</p><p>The only problem with that is Amazon only has a library to support this authentication method on the client side for Java clients only, library repository <a href="https://github.com/aws/aws-msk-iam-auth">here</a>.</p><p><strong>̶I̶f̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶o̶t̶h̶e̶r̶ ̶t̶e̶c̶h̶ ̶s̶t̶a̶c̶k̶ ̶c̶l̶i̶e̶n̶t̶s̶,̶ ̶e̶g̶.̶ ̶G̶o̶ ̶o̶r̶ ̶R̶u̶s̶t̶,̶ ̶y̶o̶u̶ ̶w̶i̶l̶l̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶s̶e̶t̶t̶l̶e̶ ̶f̶o̶r̶ ̶S̶A̶S̶L̶/̶S̶C̶R̶A̶M̶ ̶a̶u̶t̶h̶e̶n̶t̶i̶c̶a̶t̶i̶o̶n̶ ̶o̶r̶ ̶w̶r̶i̶t̶e̶ ̶t̶h̶e̶ ̶I̶A̶M̶ ̶l̶o̶g̶i̶c̶ ̶y̶o̶u̶r̶s̶e̶l̶f̶.̶</strong></p><blockquote><strong>UPDATE 2024–05–08<br>Amazon MSK IAM authentication now supports all programming languages via the SASL/OAUTHBEARER authentication mechanism.<br></strong>This is similar to the SASL IAM method, where the Kafka ACLs are defined by an IAM policy attached to an IAM role. You use a token provider that builds a temporary token used for the authentication of Kafka clients to the cluster, by calling the AWS API.<br>Check out the AWS blog post about this <a href="https://aws.amazon.com/blogs/big-data/amazon-msk-iam-authentication-now-supports-all-programming-languages/">here</a>, containing a working example for JavaScript. If you are interested to know how this works, and maybe build it for your favorite programming language, check out the implementation AWS provides for Python <a href="https://github.com/aws/aws-msk-iam-sasl-signer-python/blob/main/aws_msk_iam_sasl_signer/MSKAuthTokenProvider.py">here</a>.</blockquote><p>This brings us to the next point on the list.</p><h4>2. Kafka administration instance</h4><p>Since you’ll probably use <strong>SASL/SCRAM</strong> authentication, you probably want to set least privileged access to Kafka resources, using Kafka ACLs. For that, you’ll need an instance that can connect to the MSK cluster, with superuser permission, to set those ACLs. While you’re at it, you probably don’t want to set auto.create.topics.enable to true.</p><p>Since you don’t get remote access to the broker nodes of the Kafka cluster in MSK, you’ll need an instance to administrate Kafka.</p><p>My suggestion here is to have:</p><ul><li>an IAM role as Kafka superuser/admin — kafka-cluster:* permission</li><li>an AWS Cloud9 environment, with access to it only for Kafka administrators</li><li>on the Cloud9 environment, install Kafka tools from <a href="https://archive.apache.org/dist/kafka/3.2.0/kafka_2.12-3.2.0.tgz">here</a> and also add the MSK IAM auth library from Amazon (linked at point #1) in the <strong>libs</strong> subdirectory</li><li>use AWS Security Token Service (STS) to assume the Kafka admin role</li><li>use below client config file for <strong>kafka-*</strong> shell commands</li></ul><pre>security.protocol=SASL_SSL<br>sasl.mechanism=AWS_MSK_IAM<br>sasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;<br>sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandler</pre><p>What about Terraform, you may ask. I could only find one Terraform provider for managing Kafka resources, <a href="https://github.com/Mongey/terraform-provider-kafka">here</a>. This one doesn’t support IAM authentication as expected, so you’ll have to go through the trouble of creating an admin user with SASL/SCRAM authentication and setting appropriate Kafka ACLs for it, manually, anyway.</p><h4>3. Kafka users in Secrets Manager</h4><p>This is an interesting one and you should be aware of the limitations MSK has here. According to the <a href="https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html#msk-password-users">AWS documentation</a>:</p><ul><li>removing a user (disassociating the secret from the MSK cluster) will not close existing connections, thus if you want to enforce blocking a user, you’ll need to use Kafka ACLs</li><li>changes to user secrets can take up to 10 minutes to reflect in Kafka, so be aware in case you want to use secrets rotation, you might need to handle this in the clients</li><li>AWS Secrets Manager secrets for MSK users must use a KMS CMK and not the default Secrets Manager key — that’s because you need to allow the service role for MSK (<em>role/aws-service-role/kafka.amazonaws.com/AWSServiceRoleForKafka</em>) to use the key for decryption, kms:Decrypt</li><li>AWS Secrets Manager secrets for MSK users must have a name prefix AmazonMSK_ — this is rather annoying if you’re trying to follow a name convention across all resources in AWS</li><li>MSK cluster can have up to 1000 users, if you need to scale more you either do something wrong or you need to consider having separate clusters</li></ul><h4>4. Use a security group for clients</h4><p>When you create your MSK cluster you’ll probably create a security group for it, allowing ingress on specific ports for your desired authentication methods (9096 for SASL/SCRAM &amp; 9098 for SASL/IAM).<br>Side note: no need to add any egress rules for the cluster’s security group. Connectivity between brokers and between brokers and ZooKeeper nodes is achieved on the backbone network of AWS (not visible in your AWS account).</p><p>For the ingress rules, unless you deal with a network setup where your VPC is reachable over VPN, Direct Connect, or Transit Gateway (in these cases you need to specify IP CIDR blocks in the security group rules), you can do the following:</p><ul><li>create another security group for Kafka clients</li><li>allow ingress on the Kafka cluster security group from the Kafka clients security group</li><li>allow egress on the Kafka clients security group to the Kafka cluster security group</li><li>any Kafka clients will need to have the Kafka clients security group attached to their elastic network interface (ENI)</li></ul><h4>5. MSK Connect custom plugin</h4><p>Once you have your Kafka cluster <em>up-n-running</em> you’ll need to produce and consume data. One way to do that is to use <a href="https://kafka.apache.org/documentation.html#connect">Kafka Connect</a>.</p><blockquote>Kafka Connect is a tool for scalably and reliably streaming data between Apache Kafka and other systems</blockquote><p>Amazon has a managed service for running serverless Kafka Connect clusters, Amazon MSK Connect.</p><p>In MSK Connect you have 3 resources to work with:</p><ul><li>connector — the connector itself which defines the Kafka Connect cluster</li><li>custom plugin — a resource defining a JAR or ZIP archive (for multiple JARs) containing the connector compiled code that will be run within the Kafka Connect cluster</li><li>worker configuration — configuration for the workers started within the connector</li></ul><p>While the worker configuration is optional, the custom plugin isn’t. You need to configure this resource first, in order to use it for the connector one. When you create the custom plugin resource, you pass it the JAR or ZIP archive by specifying an S3 bucket and key where you have them stored.</p><p>One thing that you need to be aware of, <em>at the time of writing this not explicitly stated in the AWS documentation</em>, is that while the custom plugin is built with and maintains the reference to the object in S3, any updates to the object are not reflected in the custom plugin. Thus, it’s not enough to just update the package in S3 and expect at the next restart that the connector will use the new package.</p><p>You actually need to recreate (or create a new one) the custom plugin resource and then recreate (or create a new one) the connector itself.<br>Mind you, a custom plugin resource cannot be deleted if there are active connectors created with it, so you’ll need to delete the connectors first.</p><h4>6. MSK Connect topics</h4><p>Each connector will create its own set of topics in Kafka and a consumer group, required for the normal operation of the connector.</p><p>Topics:</p><ul><li>__amazon_msk_connect_configs_$connectorName_$connectorUID</li><li>__amazon_msk_connect_offsets_$connectorName_$connectorUID</li><li>__amazon_msk_connect_status_$connectorName_$connectorUID</li></ul><p>Consumer group: connect-$connectorName</p><p>When using IAM authentication for the MSK Connect connector to the MSK cluster (recommended), you’ll need to specify these topics &amp; the consumer group in the IAM policy of the connector. AWS documentation uses a more open type of policy, allowing topic actions on __amazon_msk_connect_*, but you can enforce more security by using more specific topic names.</p><p>We can spot from the above list that when we recreate a connector, although we may use the same name, a new set of topics will be created since they have the connector&#39;s unique ID in their name. These might need regular cleanup if you find yourself recreating a connector frequently.</p><p><em>Data source</em> connectors will leverage the offsets topic, so if you want a recreated connector to resume from where the previous one left off, you’ll need to specify the offsets.storage.topic property in the worker configuration to use a specific topic, rather than the default.</p><p><em>Data sink</em> connectors don’t use that offsets topic for this purpose, but rather leverage the consumer group protocol and since the consumer group contains only the connector name (and not its UID too), it will work out of the box, to resume from where the previous one left off, that is. Of course, as long as the connector name stays the same.</p><h4>7. Use AWS Secrets Manager as a Kafka config provider</h4><p>Kafka connectors support a config provider (<a href="https://kafka.apache.org/27/javadoc/org/apache/kafka/common/config/provider/ConfigProvider.html">ConfigProvider interface</a>), so you can externalize sensitive information and not have them in plain text in the connector’s configuration.</p><p>There is already one such config provider for AWS Secrets Manager, <a href="https://www.confluent.io/hub/jcustenborder/kafka-config-provider-aws">here</a>.</p><p>If for example, you are using a connector (for sourcing or sinking data) with a database, you would want to read the credentials for database access from a service like Secrets Manager, instead of having the username &amp; password in plain text in the connector configuration (visible in the AWS console).</p><p>AWS documentation is quite clear on this and has some examples too, so check it out to find more, <a href="https://docs.aws.amazon.com/msk/latest/developerguide/msk-connect-config-provider.html">here</a>.</p><h3>Conclusion</h3><p>Like other managed services, Amazon MSK has its specific inner workings that you need to be aware of while working with it, in order to not have headaches down the road. That is, besides the actual third-party service, Apache Kafka in this case, that it provides.</p><p>I’ll probably write more in the future on this topic as I face more challenges with running Kafka in production and adding more capabilities to the system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b1e56d53296" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/amazon-msk-tips-quirks-7b1e56d53296">Amazon MSK Tips &amp; Quirks</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containers: In-depth Introduction]]></title>
            <link>https://medium.com/@vtstanescu/containers-in-depth-introduction-e34fde103dd7?source=rss-71a4cf2f5337------2</link>
            <guid isPermaLink="false">https://medium.com/p/e34fde103dd7</guid>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[open-container-initiative]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Victor-Laurențiu Stănescu]]></dc:creator>
            <pubDate>Wed, 27 Apr 2022 06:28:09 GMT</pubDate>
            <atom:updated>2022-04-27T06:28:09.344Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Not what they are, but how they work.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*WncE0ifV39frFjzAAEdiwA.png" /><figcaption>High-level diagram of multiple containers hosted on the same host OS; made by the author</figcaption></figure><p>The focus of this article is to explain not what containers are, but what makes them tick.</p><p>A brief recap before we start:</p><ul><li><strong>containers</strong> are software running isolated inside a host operating-system (OS) , meaning they cannot access the whole OS, but only what the kernel allows it too. This means it is isolated from other containers running inside the same host OS too.<br> Answering the question how this is possible is the purpose of this article.</li><li>containers are started from <strong>container images</strong>, which are the actual software (aka applications) packaged , ideally, with only the dependencies it needs to run and nothing more.</li></ul><p>Benefits:</p><ul><li>easy packaging &amp; deployment</li><li>clean environments on every run/instance of your application<br> also, help keeping the host OS clean, not needing to have the dependencies of each application on it’s root file-system — thus avoiding <a href="https://en.wikipedia.org/wiki/Dependency_hell">dependency hell</a></li><li>isolation without the need of a (resource heavy) virtual-machine (VM)</li></ul><h3><strong>Isolation</strong></h3><p>Isolation is a key point for containers. Same as the virtual machines alternative, the isolation is important to reduce the blast radius for scenarios like security breaches. Since virtual machines are resource heavy, because they need to emulate hardware and provide a full, isolated, OS, and this reduces the amount of resources you can use for your own application; the need for something more lightweight came and with it OS-level virtualisation. <a href="https://en.wikipedia.org/wiki/OS-level_virtualization">OS-level virtualisation</a> is a bigger paradigm and <strong>containers</strong> represent an implementation of it.</p><h4><strong>How is this isolation achieved at OS-level?</strong></h4><p>You might have heard the phrase “Containers are Linux”. That’s because containers are, and have been for a long time, a feature of the Linux kernel. That’s because containers are processes running on Linux, like other non-containerised applications, they have their own process ID (PID). That’s why they do not required all the things a VM does.</p><p>Ok, but how is this isolation achieved, what prevents a “containerised process” to see other process running in the OS, something that a non-containerised process can do? That’s where the “a feature of Linux kernel” part comes in. Linux kernel has features that used together, build this containers and achieve their isolation. The two main parties are kernel:</p><ul><li>namespaces</li><li>control-groups (known as <strong>cgroups</strong>)</li><li>Security-Enhanced Linux (SELinux)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*gD6HM6cwsmk-SkqZb1RS8g.png" /><figcaption>Linux kernel features; diagram made by the author</figcaption></figure><h4><strong>Namespaces</strong></h4><p>Linux kernel namespaces are a way to partition the kernel resources, simply put, a mapping to actual resources of the system that a process can access. Kernel resources and associated namespaces are things like: process IDs, file systems (mount points), network, interprocess communication (IPC), users (the user namespace, introduced in Linux kernel version 3.8 is at the root of containerisation)</p><p>A Linux kernel usually starts with a default namespace for each resource and these are used by all (non-containerised) processes started on the system, but processes can create or join other namespaces.</p><h4><strong>cgroups</strong></h4><p>While <strong>namespaces</strong> is the feature used for limiting the view (and thus access) of a process, <strong>cgroups</strong> is the feature that can limit its resource utilisation, although they can do much more like prioritisation (a process getting a higher share of CPU time) and accounting (measure usage).</p><p>With this, you can prevent processes from eating away all resources of the system, which is an important part in the concept of running multiple containers under the same OS host. For eg., limiting the amount of memory of a container will likely result in that container erroring with out-of-memory (OOM) and the process hosting that container will die, but the system and other containers hosted in it will continue to live, unaffected by the erroneous container, whilst in “normal” processes, one eating away all memory (<strong>*coughing*</strong> Chrome) will make your entire system move slower if not stop responding completely (side-note: don’t forget to configured memory swap or paging to disk 🙂)</p><h4><strong>SELinux</strong></h4><p>Security-Enhanced Linux is a security module of the Linux kernel created by NSA (United States National Security Agency), that provides support for access control security policies with mandatory access controls. Without going into much detail on how SELinux works, we can understand from the policies based access control that it is a core tool in achieving the desired isolation, another line of defense.</p><p>For example, without SELinux, a compromised container that has a mounted directory from the host can still do damage, especially if the container is running as root (in the name of security don’t run your applications as root inside containers and if you really need to, ensure the UID 0 in the user namespace of the container is mapped to a different UID in the host — thus container root is not host root).</p><h3><strong>Privileged containers</strong></h3><p>Isolation in containers is not by default. You must put effort into isolating your containers, like not running your applications as root inside the container and avoiding mounting volumes from host. When you do, ensure you have other defence lines in place.</p><p>There are times when you do need such privileged containers, one eg. is running CI/CD pipelines using containers, but at some stage of your pipeline you need to build a container image. Since you are already in a container, you need a way to access the host’s container runtime, let’s use Docker as an example. To do that, you’ll mount the <strong>docker.sock</strong> from the host (usually found under <strong>/var/run/docker.sock</strong>) to your container, which will then be found by the container’s <strong>docker-cli</strong> and used to send commands such as <strong>build</strong> &amp; <strong>push</strong> to the host’s container runtime.</p><h3><strong>Open Container Initiative (OCI)</strong></h3><p>In 2015, OCI was formed as governance structure for creating open industry standards for containers formats &amp; runtimes and the two specifications of the OCI standard are: runtime-spec and image-spec.</p><p>The image specification defines how to build the container images to have required information for running the applications (command, arguments, environment etc.). Then, the runtime specification defines how to run the container image. Overall an OCI implementation will download (pull) an OCI image, unpack it as a filesystem bundle that the OCI runtime will run.</p><p>We are discussing the OCI since this is what you will most probably work with, regardless of when using containers locally (be it with the likes of Docker or Rancher Desktop) or in real-world scenarios (either with Kubernetes or cloud specific container orchestrators like Amazon Elastic Container Service aka ECS).</p><p>Let’s address container runtimes as these probably get the most confusion. The runtime has a set of responsibilities and can be categorised into two levels, based on what it does:</p><ul><li>low-level container runtimes — eg. <a href="https://github.com/opencontainers/runc">runc</a></li><li>high-level container runtimes — eg. <a href="https://github.com/containerd/containerd">containerd</a></li></ul><h4><strong>runc</strong></h4><p>This is the container runtime donated by Docker to the OCI. It’s written in Go, available as a CLI tool too, and it is considered a low-level runtime because it does the basics of running a containerised application, which as we understand by now it starts a Linux process in an isolated environments, leveraging the Linux kernel features. Instances of runc will not outlive the container process.</p><p>Other OCI runtime-spec low-level implementations is <a href="https://github.com/containers/crun">crun</a>.</p><h4><strong>containerd</strong></h4><p>This is what is considered a high-level container runtime or better, a container manager. That’s because it’s job is to manage multiple containers running on the host, pull images from registries and setup inter-container networks to name a few. Because of this, it is not a container runtime in the same way runc is. Containerd is a daemon for this purpose and actually uses a low-level container runtime like runc or crun to launch the actual containers. Worth mentioning, without going into further details, that containerd plugs in low-level container runtimes through what’s called containers-shims.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*eie07kgE9n3QSEscpxG-Ig.png" /><figcaption>Usage of OCI specifications — Kubernetes left out of the picture intentionally; diagram made by the author</figcaption></figure><h3><strong>Conclusion</strong></h3><p>That’s it, containers are a flavour of limiting the view &amp; access to resources, kind of like creating a virtual world for it — a subset of the system, and ensuring it doesn’t “eat all it can” from those resource it can access.</p><p>The focus was on Linux containers, we will address Windows containers in a separate post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e34fde103dd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>