HackMD
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Securing your JupyterHub on Kubernetes *(Thanks to Prem Mishra, Jacob Matuskey & the octraine team at the Space Telescope Sciences Institute)* Security is about tradeoffs. k8s security links & resources. https://cloud.google.com/kubernetes-engine/docs/concepts/multitenancy-overview ## API Access Many cloud providers and  ### Kubernetes API access Kubernetes is the abstraction layer we use over many machines in a cloud provider (or your own machines). API interaction with the kubernetes API is granted with Role Based Access Control (RBAC) policies. Unrestricted access to the kubernetes API is equivalent to granting users root on your entire cluster. Users generally do not need any elevated access, which can be enforced by setting a Pods `serviceAccountName` to `null` ```yaml singleuser: serviceAccountName: null ``` If you want to give users the ability to create pods, you must use PodSecurityPolicy to lock down what exactly they can create. Otherwise it is equivalent to giving them root on the cluster. In Kubernetes, this is typically handled by: - Setting a `serviceAccountName` on the pod. - Creating a `ServiceAccount` - Creating a `Role` with sufficient permissions to create new pods. - Creating a `RoleBinding` to connect the `ServiceAccount` to the `Role` ```yaml apiVersion: v1 kind: ServiceAccount metadata: name: name --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: name rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods", "persistentvolumeclaims"] verbs: ["get", "watch", "list", "create", "delete"] - apiGroups: [""] # "" indicates the core API group resources: ["events"] verbs: ["get", "watch", "list"] --- kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: name subjects: - kind: ServiceAccount name: name namespace: namespace roleRef: kind: Role name: name apiGroup: rbac.authorization.k8s.io ``` ### Cloud metadata access ```yaml singleuser: cloudMetadata: enabled: false ``` ## Container security ### Don't allow users to be root ```yaml hub: extraConfig: 01-no-root: | c.KubeSpawner.extra_container_config = { 'securityContext:' { 'runAsUser': 1000, 'privileged': False, 'allowPrivilegeEscalation': False } } ``` ### Giving each user a separate uid BIG PAIN IN THE ASS. Means you can't use any off-the-shelf images, gotta build your own Needs a lot more docs lol https://docs.openshift.com/container-platform/3.3/creating_images/guidelines.html#openshift-container-platform-specific-guidelines is the core concept ### seccomp https://github.com/kubernetes/enhancements/pull/1148 ### AppArmor * Note: Don't say anything about SELinux * https://kubernetes.io/docs/tutorials/clusters/apparmor/ ## Storage security ### Block vs File storage #### Block Storage:  Much better isolation between users Much better performance for users Much better quota'ing for users More expensive, based on your usage pattern Start / stop times higher Can be mounted on only one container at a time Higher failure rates based on your cloud provider in attach / detach Constrains size of each node, since most cloud providers have a limit on number of disks that can be attached to each node #### File storage Much cheaper, because you can overcommit! Faster attach / detach Can be mounted in multiple places Managing your own NFS server is work Managed NFS providers have issues based on what kinda work you are doing Worse performance, magnified based on your workload Quotas are hard ### Secure NFS mounting Currently, people use: One PV referring the NFS share One PVC that attaches to this subPaths in each pod's volume mount to show only their home directory to the user This mounts the entire NFS share on the host node, and then bind mounts the subPath for each user's home directory. If the user can break out of the container, they can now read *every other user's* home directories, especially if the uid is the same for all users. An alternative is to use something like nfs-client-provisioner, and create one PVC per user automatically. This will bind to a new PV that is *just* the home directory of the user, so the entire NFS share isn't mounted on all nodes. If there's a container breakout, the user can only see the home directories of other users in the same host, not everywhere. You can make this a little more secure by giving each of your users their own uid. ## Network Security ### HTTPS Have HTTPS between your users and the hub. Pretty simple these days with our Let's Encrypt integration. ### Internal TLS? Depending on what you want, might be needed between components. JupyterHub itself supports it, but I think KubeSpawner doesn't yet - so can't be used on Kubernetes. Consider something like LinkerD or istio in the meantime - although they are probably extremely heavyweight for what you need, and add a lot of extra complexity. ### NetworkPolicy between components Easy win! ```yaml hub: networkPolicy: enabled: true proxy: networkPolicy: enabled: true singleuser: networkPolicy: enabled: true ``` ### Restrict outbound network access ```yaml singleuser: networkPolicy: enabled: true egress: - ports: - port: 53 protocol: UDP - ports: - port: 80 protocol: TCP - ports: - port: 443 protocol: TCP ``` ### Network bandwidth limitation Depending on how your k8s cluster is set up (network plugin), you can limit it via annotations: ```yaml singleuser: extraAnnotations: kubernetes.io/ingress-bandwidth: 1M kubernetes.io/egress-bandwidth: 1M ``` If not, you can use minrk's tc-init to limit outbound traffic. ## Resource exhaustion A user can use up way more resources than they should, thus denying other users resources they legitimately have access to. CPU / RAM requests & limits limits vs guarantees. overcommit Filesystem usage block store Automatically set by your request size. Can grow if your provider supports it. filestore No beuno! Unless you run your own NFS server with XFS, then you can use project quotas. Other resources Temporary disk space PID Limits https://kubernetes.io/blog/2019/04/15/process-id-limiting-for-stability-improvements-in-kubernetes-1.14/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully