<commit_before>
# SSH

    misc = require 'mecano/lib/misc'
    each = require 'each'
    exports = module.exports = []
    exports.push 'masson/bootstrap'
    exports.push 'masson/core/users'
    exports.push 'masson/core/yum'

## Configuration

Configuration extends the configuration of the "masson/core/users" with
new properties "authorized\_keys", "rsa" and "rsa_pub" and also define 
two new properties "sshd\_config" and "banner".

*   `users.[].authorized_keys` (string, array)   
    A list of SSH public keys added to the "~/.ssh/authorized_keys" file, optional.   
*   `users.[].rsa` (string)   
    Private SSH key of the user, optional.
*   `users.[].rsa_pub` (string)   
    Public SSH key of the user, optional.
*   `ssh.sshd_config` (object)   
    Configure the SSH daemon by updating the "/etc/ssh/sshd_config" file with 
    key/value properties, optional.   
*   `ssh.banner` (object)   
    Write a banner file in the system and register it with the "/etc/ssh/sshd_config" file, optional.   
       

```json
{
  "users": [{
    "name": "root"
    "authorized_keys": [ "ssh-rsa AAAA...ZZZZ me@email.com" ],
    "rsa": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCA...PKToe4z7C9BqMT7Og==\n-----END RSA PRIVATE KEY-----"
    "rsa_pub": "ssh-rsa AAAA...YYYY user@hadoop"
  },{
    "name": "sweet"
    "home": "/home/sweet" 
    "authorized_keys": [ "ssh-rsa AAAA...XXXX <EMAIL>.<EMAIL>" ]
  }]
  "ssh": {
    "sshd_config": {
      "UsePAM": "yes"
      "Port": 2222
    },
    "banner": {
      "destination": "/etc/banner",
      "content": "Welcome to Hadoop!"
    }
  }
}
```

    exports.push (ctx) ->
      require('./users').configure ctx
      ctx.config.ssh ?= {}
      ctx.config.ssh.sshd_config ?= null
      for _, user of ctx.config.users
        user.authorized_keys ?= []
        user.authorized_keys = [user.authorized_keys] if typeof user.authorized_keys is 'string'

## Authorized Keys

Update the "~/.ssh/authorized_keys" file for each users and add the public SSH keys
defined inside "users.[].authorized_keys".

    exports.push name: 'SSH # Authorized Keys', timeout: -1, handler: (ctx, next) ->
      modified = false
      users = for _, user of ctx.config.users then user
      each(users)
      .on 'item', (user, next) ->
        return next() unless user.home
        ctx.mkdir 
          destination: "#{user.home or '/home/'+user.name}/.ssh"
          uid: user.name
          gid: null
          mode: 0o700 # was "permissions: 16832"
        , (err, created) ->
          return next err if err
          write = for key in user.authorized_keys<commit_msg>allow empty key for authorized_key<commit_after>
# SSH

    misc = require 'mecano/lib/misc'
    each = require 'each'
    exports = module.exports = []
    exports.push 'masson/bootstrap'
    exports.push 'masson/core/users'
    exports.push 'masson/core/yum'

## Configuration

Configuration extends the configuration of the "masson/core/users" with
new properties "authorized\_keys", "rsa" and "rsa_pub" and also define 
two new properties "sshd\_config" and "banner".

*   `users.[].authorized_keys` (string, array)   
    A list of SSH public keys added to the "~/.ssh/authorized_keys" file, optional.   
*   `users.[].rsa` (string)   
    Private SSH key of the user, optional.
*   `users.[].rsa_pub` (string)   
    Public SSH key of the user, optional.
*   `ssh.sshd_config` (object)   
    Configure the SSH daemon by updating the "/etc/ssh/sshd_config" file with 
    key/value properties, optional.   
*   `ssh.banner` (object)   
    Write a banner file in the system and register it with the "/etc/ssh/sshd_config" file, optional.   
       

```json
{
  "users": [{
    "name": "root"
    "authorized_keys": [ "ssh-rsa AAAA...ZZZZ <EMAIL>" ],
    "rsa": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCA...PKToe4z7C9BqMT7Og==\n-----END RSA PRIVATE KEY-----"
    "rsa_pub": "ssh-rsa AAAA...YYYY user@hadoop"
  },{
    "name": "sweet"
    "home": "/home/sweet" 
    "authorized_keys": [ "ssh-rsa AAAA...XXXX <EMAIL>" ]
  }]
  "ssh": {
    "sshd_config": {
      "UsePAM": "yes"
      "Port": 2222
    },
    "banner": {
      "destination": "/etc/banner",
      "content": "Welcome to Hadoop!"
    }
  }
}
```

    exports.push (ctx) ->
      require('./users').configure ctx
      ctx.config.ssh ?= {}
      ctx.config.ssh.sshd_config ?= null
      for _, user of ctx.config.users
        user.authorized_keys ?= []
        user.authorized_keys = [user.authorized_keys] if typeof user.authorized_keys is 'string'

## Authorized Keys

Update the "~/.ssh/authorized_keys" file for each users and add the public SSH keys
defined inside "users.[].authorized_keys".

    exports.push name: 'SSH # Authorized Keys', timeout: -1, handler: (ctx, next) ->
      modified = false
      users = for _, user of ctx.config.users then user
      each(users)
      .on 'item', (user, next) ->
        return next() unless user.home
	return next() unless user.authorized_keys.length
        ctx.mkdir 
          destination: "#{user.home or '/home/'+user.name}/.ssh"
          uid: user.name
          gid: null
          mode: 0o700 # was "permissions: 16832"
        , (err, created) ->
          return next err if err
          write = for key in user.authorized_keys
{'fraction_non_alphanumeric': 0.1454304133485021, 'fraction_numerical': 0.006825938566552901, 'mean_word_length': 2.530789825970549, 'pattern_counts': {'":': 30, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '187176', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1715, 'n_words': 481}