Code Monkey home page Code Monkey logo

workspaces-ssm-install's Introduction

Automate SSM client Installation on Workspaces

This is a solution designed to automate installation & registration of Workspaces as SSM clients. It also adds Tags to the Managed instance (Workspace ID, Assigned User, Directory ID, Region, Hostname and OS along with the AD groups the user is assigned). The AD tags are Dynamic and change as Users AD group memberships change. These Tags can be used a way to create Target groups for SSM tasks such as Pachting, Package Deloyment and Run Command

With Automated Installation of SSM agent, you can use SSM tools such as Patch Managent, run Command, Automation and Distributor to Patch, deploy software and run compliance checks on your Workspace Fleet. You can also use SSM to Monitor managed node performance for troubleshooting purposes.

alt text

Usage

The Solution contain the following

  • SAM Template that deploys the API Gateway and the Lambda Function
  • Powershell Script that is deployed to the Workspace Image that automates SSM Agent download, install and configuration

Steps to deploy the solution

Deploy Server Side Stack

  • Clone the Repo to a machine that is configured to deploy resources in AWS.

  • Setup AWS SAM CLI Make sure to follow the steps on installing Docker based on the OS of your choice as we use Docker images

  • Build and deploy the SAM application

      sam build
      sam deploy --guided
    
  • Provide the Parameters for Region, DNS IP of the AD server, Subnet and security groups for the Lambda function to be created.

  • The Lambda script that adds Users AD groups as Tags to the Managed instance needs AD credentials to make LDAP calls. Create a AD user with rights to get users group membership. The template prompts to enter the AD Username.

  • Save the AD password as a Secret of type 'Plaintext' in AWS Secrets Manager as explained here

  • In the Stack output, you get the API Gateway endpoint thats needed for the Powershell script configuration. alt text

Deploy Script on Workspace

The client side script is written in Powershell that works on both windows and Linux. Install Powershell 7 on a workspace before continuing.

Steps to install powershell on windows

Steps to install powershell on Amazon Linux

  • Clone the Repo to the workspace that is going to have the script installed and be used for Imaging

  • Open Powershell 7 command Prompt as Administrator

  • Follow the steps below

      cd workspaces-ssm-install
      cd clientscripts
      ./createscript.ps1
    

The script prompts to enter the API endpoint URL that was created in the Previous step

  • The script does the following based on the OS

    Windows

    • copies the script to C:\ProgramData\ssm_script
    • Creates a scheduled Task to run the script on startup and on schedule

    Linux

    • copies the script to /usr/local/bin
    • creates systemd service and timer

Take an image of the workspace

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

workspaces-ssm-install's People

Contributors

amazon-auto avatar ramammah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

workspaces-ssm-install's Issues

DynamoDB Table Definition Missing

The Lambda Function, TaggerSQSWorker makes reference to a DynamoDB table with a default name of, WS_SSM_tag_data.

DynamoTable:
Type: String
Description: The name of the secret that has the password for the AD user stored
Default: 'WS_SSM_tag_data'

However, based on the description, this is a copy/paste error as that's the exact same description in-use for the Active Directory password. I don't see any reference to a DDB table creation in the Cloud Formation template, so I'm assuming this was meant to have been created manually outside of the solution proper.

Could you please include instructions on how to create this table? I suspect that also means the IAM role associated with this Lambda would also need to be updated accordingly to make queries against DDB. Presently, there's no IAM policy present to allow this.

Thank you!

Race Condition Creates Infinite SSM Hybrid Activations

You've got a race condition happening when a Workspace wakes up from suspend. When this happens, your service timer realizes its missed its most recent invocation (every 24hrs), and immediately tries to execute.

When this happens, it's sometimes before the SSM-Agent has had a chance to handshake with the SSM service. When this happens, the script obtains a "not_found" response for the SSM ping status-check.

Once it does that, it assumes it's un-registered and proceeds to request a new registration code and ID from SSM, which it successfully uses to register itself as a fresh entity within SSM. This, of course, loses all historical record and reporting as according to SSM, this is a new, never seen before instance.

I know there's a boot-up timer delay baked into the service startup, but this is happening when a workspace resumes so that 300 second timer after boot-up isn't in-play here.

To remedy this, I've had to increase the Pre-Execution sleep timer in the ssminstall.service file as follows:

[Service]
ExecStartPre=/bin/sleep 300
ExecStart=/usr/bin/pwsh /usr/local/bin/finalmultiplatformloginscript.ps1
Type=oneshot

The original value had been just 15 seconds, which is not long enough for the SSM agent to fully handshake with the SSM service. I suspect 300 seconds is far longer than necessary, but there's really no harm in having it wait longer just as long as it gets there eventually.

Another side-effect of this issue is that every time a workspace boots, it gets a NEW activation so once you fix this, make sure to go back and remove all of the old defunct hybrid activations from SSM. I had over 300 activations for 40 workspaces before I realized what was happening and fixed it.

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.