Giter Site home page Giter Site logo

charlesportwoodii / drone-teleport Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 1.62 MB

A drone plugin for executing remote commands over SSH, through Teleport Machine IDs

License: BSD 3-Clause "New" or "Revised" License

Dockerfile 3.00% Rust 97.00%
drone drone-ci drone-plugin tbot teleport tsh

drone-teleport's Introduction

Drone Teleport

A drone plugin for executing remote commands over SSH, through Teleport Machine IDs.

Build Status Latest Version Docker Pulls

This project is not sponsored, supported, or endorsed by Graviton or Teleport in any capacity.

Drone Usage

This plugin supports two specific operations, defined by the op argument: connect and transfer.

NOTE: Your Drone instance must have a working Teleport Bot / Machine ID configuration active and available at /opt/teleport/home, or elsewhere on disk, and must be mounted into the container. Take a look at the Teleport Machine ID Getting Started Guide for more information on how to set this up.

Connect

demo

Connect is utilized to connect to an SSH target and run commands. Example arguments are as follows.

volumes:
  - name: teleport-ssh
    host:
      path: /opt/teleport/home

steps:
  - name: "drone-teleport"
    image: charlesportwoodii/drone-teleport:latest
    volumes:
      - name: teleport-ssh
        path: /opt/teleport/home
    settings:
      op: connect
      proxy: teleport.example.com
      hosts:
        - host1.teleport.example.com
      username: ci
      data_path: /opt/teleport/home
      env:
        CUSTOM_ENV: "custom-env"
        CUSTOM_ENV2: "custom-env2"
      script:
        commands:
          - id
          - whoami
          - ls -laht | awk '{ print $1 }'
          - echo ${DRONE_COMMIT_SHA}
          - echo a{b,c,d} | tr ' ' ,

Transfer

demo

The transfer op may be utilized to transfer files from the source to the destination. Glob patterns are supported

Files are transfered in ~ 8Mb buffers. Multiple hosts are supported.

volumes:
  - name: teleport-ssh
    host:
      path: /opt/teleport/home

steps:
  - name: "drone-teleport"
    image: charlesportwoodii/drone-teleport:latest
    volumes:
      - name: teleport-ssh
        path: /opt/teleport/home
    settings:
      op: transfer
      proxy: teleport.example.com
      compress: true
      compress_level: 13
      hosts:
        - host1.teleport.example.com
        - host2.teleport.example.com
      username: ci
      data_path: /opt/teleport/home
      files:
        - src: /path/to/file
           dst: /remote/file
        - src: /path/to/dir/*
           dst: /path/to/dir/
        - src: /path/**/*
           dst: /path/blob

drone-teleport will automatically create an archive of all files in src and compress them for transfer using zstd. Make sure your remote tar program is at least version >=1.31 and has support for zstd built in. Compression is done with compression level of 13 by default and is configured via compress_level option, and can be disabled entirely by setting compress to false.

NOTE: If you need to grab all files including hidden files, It's recommended to add a depends_on previous step that creates a single tar archive, then set that as the src instead of adding multiple src/dst file targets, then extracting that on the remote target. NOTE: File transfer is destructive on the remote target. drone-teleport will overwrite any existing files on the remote without warning. Make sure your dst argument is valid before executing!

Docker Usage

Execute from the working directory:

docker run --rm \
    -e PLUGIN_OP=connect|transfer
    -e PLUGIN_DATA_PATH=/opt/teleport/home \
    -e PLUGIN_HOSTS=host1.teleport.example.com,host2.teleport.example.com \
    -e PLUGIN_USERNAME=ci \
    -e PLUGIN_SCRIPT="{\"commands\":[\"id\",\"whoami\",\"ls -laht | awk '{ print $1 }'\",\"echo c8f794eb0249dc0af9987656ec7b09f9bc0c1d8a\",\"exit 1\", \"asdfasdf\",\"echo a{b,c,d} | tr ' ' ,\"]}" \
    -e PLUGIN_ENV="{ \"CUSTOM_ENV\": \"custom-env\" }" \
    -e PLUGIN_DEBUG=false \
    -e PLUGIN_PORT=3022 \
    -e PLUGIN_PROXY=teleport.example.com \
    -e PLUGIN_CLUSTER=teleport.example.com \
    -e PLUGIN_FILES="[{ \"src\": \"source-file\",  \"dst\": \"destination-file\"}]"
    -v${PWD-.}:${PWD-.} \
    -v${PWD-.} \
    -v/opt/teleport/home:/opt/teleport/home \
    charlesportwoodii/drone-teleport:latest

Building

Binary can be built using cargo. Make sure you have the rust toolchain installed. aarch64 and amd64 architectures are both supported.

cargo build --release --target x86_64-unknown-linux-gnu
cargo build --release --target aarch64-unknown-linux-gnu

Docker image is managed via Drone pipeline, but can be built manually with buildx.

docker buildx build --platform linux/amd64,linux/arm64 -t charlesportwoodii/drone-teleport:latest  --no-cache .

NOTE: Reference the .drone.yml Cargo Build section for the appropriate packages for cross-compilings for amd64 and arm64.

Drone Repository Configuration

Please ensure that trusted mode is enabled in your drone repository settings to allow mounted volumes.

demo

Execution Notes

This plugin will execute commands in parallel for all listed servers and will stop on any error.

drone-teleport's People

Contributors

charlesportwoodii avatar

Stargazers

 avatar

Watchers

 avatar  avatar

drone-teleport's Issues

Terminate all error handler

In then event any task encounters an error, all task should be terminated rather than allowing the other to continue in a more graceful way than exit 1

Command Timeout

Implement command timeout to forcefully kill commands that take longer than cfg.timeout seconds to complete.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.