Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run node shell on Bootlerocket and Windows nodes #7965

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dex4er
Copy link
Contributor

@dex4er dex4er commented Oct 23, 2023

This is a reworked node-shell feature. It allows to run it on Bottlerocket OS and Windows nodes where there is no sh nor bash command.

Unfortunately, node-shell pods cannot be autoremoved anymore with sleep command. It is because now single pod is created and then kubectl attach is run. It is because kubectl exec with nsenter command won't work: Bottlerocket OS is SELinux hardened then nsenter won't have privileges to run in kubectl exec context.

Anyway: node-shell pods are correctly removed after the terminal is closed.

Because Windows needs separate image, there is a separate setting now:

image

Node shell for Ubuntu:

image

Node shell for Bottlerocket:

image

Node shell for Windows 2022:

image

@dex4er dex4er requested a review from a team as a code owner October 23, 2023 09:09
@dex4er dex4er requested review from ixrock and aleksfront and removed request for a team October 23, 2023 09:09
@dex4er dex4er force-pushed the feature/node-shell-windows branch from 00eb857 to 83b2ce6 Compare October 23, 2023 09:09
@moebaca
Copy link

moebaca commented Feb 13, 2024

Any update on this? Would love to pop into Bottlerocket using Lens like I do for AL2.

@ajaykumarmandapati
Copy link

Would this be available soon? 🙏🏾

@ixrock ixrock requested review from a team, ixrock and Nokel81 and removed request for ixrock, aleksfront and a team April 8, 2024 07:07
@matti
Copy link

matti commented Feb 8, 2025

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The logic for determining the nodeOsImage and setting the args for Bottlerocket OS nodes may not handle edge cases where nodeOsImage is undefined or does not start with "Bottlerocket OS". Ensure this logic is robust and properly tested.

const nodeOs = node.getOperatingSystem();
const nodeOsImage = node.getOperatingSystemImage();

let image: string;
let command: string[]; 
let args: string[];
let securityContext: any;

switch (nodeOs) {
  default:
    this.dependencies.logger.warn(`[NODE-SHELL-SESSION]: could not determine node OS, falling back with assumption of linux`);
    // fallthrough
  case "linux":
    image = nodeShellImage || initialNodeShellImage;
    command = ["nsenter"];

    if (nodeOsImage && nodeOsImage.startsWith("Bottlerocket OS")) {
      args = ["-t", "1", "-m", "-u", "-i", "-n", "-p", "--", "apiclient", "exec", "admin", "bash", "-l"];
    } else {
      args = ["-t", "1", "-m", "-u", "-i", "-n", "-p", "--", "bash", "-l"];
    }

    securityContext = {
      privileged: true,
    };
    break;
  case "windows":
    image = nodeShellImage || initialNodeShellWindowsImage;
    command = ["cmd.exe"];
    args = ["/c", "%CONTAINER_SANDBOX_MOUNT_POINT%\\Program Files\\PowerShell\\latest\\pwsh.exe", "-nol", "-wd", "C:\\"];
    securityContext = {
      privileged: true,
      windowsOptions: {
        hostProcess: true,
        runAsUserName: "NT AUTHORITY\\SYSTEM",
      },
UI Consistency

The addition of separate inputs for Linux and Windows node shell images introduces potential UI inconsistency. Ensure the UI design and user experience are intuitive and aligned with the rest of the application.

  <SubTitle title="Node shell image for Linux" id="node-shell-image"/>
  <Input
    theme="round-black"
    placeholder={`Default image: ${initialNodeShellImage}`}
    value={this.nodeShellImage}
    onChange={value => this.nodeShellImage = value}
    iconRight={
      this.nodeShellImage
        ? (
          <Icon
            smallest
            material="close"
            onClick={() => this.nodeShellImage = ""}
            tooltip="Reset"
          />
        )
        : undefined
    }
  />
  <small className="hint">
    Node shell image. Used for creating node shell pod on Linux nodes.
  </small>
</section>
<Gutter />
<section>
  <SubTitle title="Node shell image for Windows" id="node-shell-windows-image"/>
  <Input
    theme="round-black"
    placeholder={`Default image: ${initialNodeShellWindowsImage}`}
    value={this.nodeShellWindowsImage}
    onChange={value => this.nodeShellWindowsImage = value}
    iconRight={
      this.nodeShellWindowsImage
        ? (
          <Icon
            smallest
            material="close"
            onClick={() => this.nodeShellWindowsImage = ""}
            tooltip="Reset"
          />
        )
        : undefined
    }
  />
  <small className="hint">
    Node shell image. Used for creating node shell pod on Windows nodes.
  </small>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants