Giter Club home page Giter Club logo

hdm's Introduction

HDM - Hiera Data Manager

Hiera Data Manager logo

Copyright 2023 betadots GmbH

This Rails application displays Puppet Hiera data and offers a WebGUI to read/update/create that configuration.

You can find screenshots in the screenshots.

Manual installation

At the moment manual installation is only tested on macOS, CentOS 7 and 8 Streams. But we highly recommend to use the Docker image!

See MANUAL_INSTALL.md

Automated installation

Docker containers are made available. You can find more information in DOCKER.md. For automated installations we recommend using Puppet code. A working profile example can be found in PUPPET.md

Configuration Options

HDM needs a configuration file (hdm.yml). Location depends on installation method:

  • Manual installation: within the HDM git clone in config/hdm.yml
  • Docker installation: on the docker host in /etc/hdm/hdm.yml

Configurations are provided as a Hash. The main hash key describes the Rails environment HDM is running in:

  • Manual installation: depending on RAILS ENVIRONMENT env var - defaults to development
  • Docker installation: set to production

The following configuration options are possible:

# hdm.yml
production:
  authentication_disabled: false    # disable user auth and management

  read_only: true                   # read/write mode?

  allow_encryption: false           # encypting eyaml

  puppet_db:                        # PuppetDB access - plain text (default)
    server: http://localhost:8080
  puppet_db:                        # PuppetDB access-  PE token auth
    server: 'https://localhost:8081'
    token: '/etc/hdm/puppetdb.token'
    cacert: '<path to cacert>'
  puppet_db:                        # PuppetDB access - SSL Cert auth
    server: 'https://localhost:8081'
    pem:
      key: <path to key>
      cert: <path to cert>
      ca_file: <path to ca_file>

  hiera_config_file: "hiera.yaml"   # hiera config file name

  config_dir: /etc/puppetlabs/code  # puppet code directory

  global_hiera_yaml: /etc/puppetlabs/puppet/hiera.yaml

  base_module_path: "/etc/puppetlabs/puppet/code:/opt/puppetlabs/puppet/modules" # optional, in case you overwrite `basemodulepath` in puppet.conf

  ldap:                             # LDAP User auth
    host: 'localhost'
    port: 389
    base_dn: 'ou=hdm,dc=nodomain'
    bind_dn: 'cn=admin,dc=nodomain'
    bind_dn_password: 'openldap'
    ldaps: false

Usermanagement

Usermanagement can be disabled in HDM config file by specifying the authentication_disabled option.

A fresh installation needs an admin which has to be created first with the WebGUI. That admin can not read the Puppet configuration. He/She can only create/delete new users. Normal users have the ability to read/change/delete the Puppet configuration data.

Use git repositories instead of "live" yaml files

HDM can edit live hiera yaml files directly in the file system. While this might be fine for smaller installations, it might not be desireable in many others.

In those cases you should make sure that the user HDM runs as has no write access to the files. If you still want to be able to make changes, you should consider making them in a git repository instead. This will afford you a full history of edits and the possibility to roll back changes if necessary.

HDM supports this by allowing you to substitute directories from the file system hosting the live hiera files with directories from a git repository.

Say your live data lives in /etc/puppetlabs/code/myenv/data. To replace this with data from the git repository at githost.example.com:puppet/hiera_data.git where the corresponding directory is called environments/myenv/data add the following to config/hdm.yml:

production:
  # ... existing production config ...
  git_data:
    - datadir: /etc/puppetlabs/code/myenv/data
      git_url: [email protected]:puppet/hiera_data.git
      path_in_repo: environments/myenv/data

You can substitute as many directories with ones from git repositories as you like.

Please note that the user HDM runs as needs to be able to clone the repository. Cloned repos are stored in HDM's repos directory. Repositories are cloned the first time they are needed. This might take a long time, so HDM also provides a task to prefetch all needed repositories:

bundle exec rails hdm:clone_repos

Any changes made to files from a git repository will be commited and pushed back to the origin repository. Please note that HDM will not pull updates from the origin repository and is not able to resolve possible conflicts, so you might want to make sure that your repository is only edited by HDM.

⚠️ Update to >= 1.0.0

Set rails secret

Don't forget to set SECRET_KEY_BASE env var in docker run, docker-compose, systemd or hieradata.

openssl rand -hex 16
9dea7603c008dec285e4b231602a00b2

SECRET_KEY_BASE="9dea7603c008dec285e4b231602a00b2"


docker run -it --rm -p 3000:3000 -e DEVELOP=1 -e SECRET_KEY_BASE=9dea7603c008dec285e4b231602a00b2 ghcr.io/betadots/hdm:development

See docker-compose.yaml.

Update db file

Move existing db/development.sqlite3 to db/production.sqlite3

docker exec -it <container_id> bash
mv db/development.sqlite3 db/production.sqlite3
bin/rails db:environment:set RAILS_ENV=production

How to contribute?

see CONTRIBUTING.md

hdm's People

Contributors

bastelfreak avatar dan33l avatar dependabot[bot] avatar gguillotte avatar github-actions[bot] avatar marcusdots avatar oneiros avatar phortx avatar rwaffen avatar tuxmea avatar wintermeyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hdm's Issues

Running Rails in production mode

  • assets precompile: bundle exec rails assets:precompile
  • ENV: RAILS_ENV=production
  • Puppet-HDM Module:
    • database.yml
    • production.sqlite3

Docker images and labels

When building on a tag: the tag is available as latest
When building on main, this build should not be tagged as latest, but as development (maybe also main).

move "listen" gem out of development group?

when i bundle without development, the app does not start.
but if i understand this right, from concept, development group shouldn't be necessary for a production run?

hdm  | rails aborted!
hdm  | LoadError: cannot load such file -- listen
hdm  | /hdm/config/environments/development.rb:75:in `block in <top (required)>'
hdm  | /hdm/config/environments/development.rb:3:in `<top (required)>'
hdm  | /hdm/config/environment.rb:5:in `<top (required)>'
hdm  | Tasks: TOP => db:create => db:load_config => environment
hdm  | (See full trace by running task with --trace)

to fix this, i moved the listen gem out of the development group.

Edge case: PuppetDB still has an information regarding an environment, but the environment does no longer exist on file system

Usually we have short living feature branch based environments.

Consider that someone creates the feature branch, runs a single node against the feature branch, and merges his change.
In this case the code deployment will remove the feature branch environment from file system, PuppetDB will get updated, when Puppet agent is running the next time.

Within HDM:

  1. we get a list of environments from PuppetDB
  2. we select an environment and query PuppetDB for nodes

Desired solution:

  1. HDM queries PuppetDB for environments
  2. prior showing the list HDM checks if any of the returned environments is no longer available on file system and marks the unavailable environments as non-selectable in the drop-down menu

HDM should be able to use 80% browser window width.

When running browser in fullscreen, the content is centered and uses maybe 50% of window width.

HDM should use 80% of window width if possible for the data content.
It is ok to keep the hiera key width as is.

Update to ruby 3.2.x

container build is atm on ruby 3.1.3, we want to update this to 3.2.1 or newer.

Define a CI/CD strategy

Some thoughts about a CI/CD strategy that could be implemented. This is based on my experience with vox-pupuli-tasks (also a Rails application) and the different gems Vox Pupuli hosts:

Enable dependabot alerts

  • GitHub will scan the Gemfile.lock for potential updates and CVEs in dependencies daily

Define a GitHub action that runs on pull requests:

  • Define the lowest Rubyversion we support
  • Run rubocop with that Rubyversion as target
  • Define a list of Ruby versions we want to support + latest ruby
  • Use that as a matrix where we run the following for each ruby version
  • Run the existing rspec tests in a matrix on each Ruby version
    • On one Ruby version, run codecov for coverage reporting
    • Run brakeman for Rails specific reporting
  • build the application (generating assets...)
  • Start the application and validate some http endpoints

Define a GitHub action that runs on merges

  • Apply the action from above
  • Build a docker image
    • publish it at least to github container registry
    • Tag the image with the commit sha
    • Tag it also with latest or testing
    • Start the application via docker-compose with the new Image+dependencies
  • build at least rpms+debs and upload them

Define a GitHub action that runs on tags

  • same as above, but tag packages/images with the name of the pushed tag, not a commit sha

Additional Resources

Allow reset of admin password

something like: bundle exec rake db:admin:reset:<username> should be possible.
Return value should be a new random password

Hiera accepts empty yaml files

The following data produce no error in hiera:

---
# comment

HMD YAML parser complains about NIL.

When adding the curly braces, HDM will not complain:

--- {}
# comment

Accept NIL data and continue to follow Hiera behavior

Error if datadir is not set in hiera.yaml

is datadir is not set in hiera.yaml, one gets an error in the intrface about datadir being empty/nil.

datadir is not mandatory in hiera.yaml, if not set, it is assumed to be "data".

Dependabot - RCE bug with Serialized Columns in Active Record

https://github.com/betadots/hdm/security/dependabot/77

 Dependabot cannot update activerecord to a non-vulnerable version

The latest possible version that can be installed is 7.0.2.4 because of the following conflicting dependencies:

rails (7.0.2.4) requires activerecord (= 7.0.2.4) via actionmailbox (7.0.2.4)
rails (7.0.2.4) requires activerecord (= 7.0.2.4) via actiontext (7.0.2.4)
rails (7.0.2.4) requires activerecord (= 7.0.2.4) via activestorage (7.0.2.4)
rails (7.0.2.4) requires activerecord (= 7.0.2.4)

The earliest fixed version is 7.0.3.1.

Custom 40x Error Page?

Static public error pages.
No need to be 100% identical to HDM web UI.
More important: where should a user look for data errors.

HTTP error codes:

  • 422 - rails default for API results (unprocessible entity)
  • 404 - not found - e.g. typo in URL
    • short message: check the URL
    • home button
  • 500 - internal server error
    • NIL yaml data
    • link to issue on github
    • hint to check logfile
    • home button
  • 403 - no auth, not privileged/authorized
    • hint: not logged in, user gets admin URL, general permissions
    • home button

License

Open Source. Check dependencies.

Allow API usage

Idea is to have an API endpoint where we can query for results.

e.g.

POST http://<server>:<port>/api/v1/data?env=production&node=node.domain.tld&key=classes or
http://<server>:3000/environments/production/nodes/puppet.matest.betadots.training/keys/classes?search=&format=json

Result (needs review and optimization)

{
  'yaml hierarchy': [
    {
      'nodes/puppet.yaml': 'RESULT'
    }
  ],
  'defaults': [
    {
      'defaults/auditbeat.yaml': 'RESULT'
    },
    {
      'defaults/filebeat.yaml': 'RESULT'
    },
  ]
  'common': [
    {
      'common.yaml': 'RESULT'
    }
  ]
}

RAILS is capable to provide different data format based on URL.
Do we want users to have a specific role to access API.
Basic Authentication is possible.

Add SSL offloading information

when installing a new hdm instance and having no users, one gets redirected to http to create a new user. but connection was initialized from https. we schould redirect to the same protocol as the initial reuqest

HDM does not recognize the facts. syntax in hiera.yaml file

In hiera.yaml file one can specify a fact in multiple ways.

  1. Top Scope Variable (Using :: syntax like %{::customer})
  2. Facts Hash (Using facts. syntax like %{facts.customer})

At the moment HDM only recognizes option 1.
HDM should be able to also understand and parse the option 2.

Some people might use %{::environment} in Hiera.yaml.
This is not a fact but should have the content from the selected environment.

barrier free UI

Some customers may only use web-interfaces which follow a "barrier free" concept.

Possible steps:

  • black/white UI - better: contrast.
  • ALT Naming to any field/button?
  • Red/Green should not be paired.

Docker Run: ExecJS::RuntimeUnavailable

hdm  | rails aborted!
hdm  | ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
hdm  | /usr/local/bundle/gems/execjs-2.8.1/lib/execjs/runtimes.rb:58:in `autodetect'
hdm  | /usr/local/bundle/gems/execjs-2.8.1/lib/execjs.rb:5:in `<module:ExecJS>'
hdm  | /usr/local/bundle/gems/execjs-2.8.1/lib/execjs.rb:4:in `<top (required)>'
hdm  | /usr/local/bundle/gems/autoprefixer-rails-10.4.7.0/lib/autoprefixer-rails/processor.rb:4:in `require'
hdm  | /usr/local/bundle/gems/autoprefixer-rails-10.4.7.0/lib/autoprefixer-rails/processor.rb:4:in `<top (required)>'
hdm  | /usr/local/bundle/gems/autoprefixer-rails-10.4.7.0/lib/autoprefixer-rails.rb:39:in `require_relative'
hdm  | /usr/local/bundle/gems/autoprefixer-rails-10.4.7.0/lib/autoprefixer-rails.rb:39:in `<top (required)>'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap/engine.rb:3:in `require'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap/engine.rb:3:in `<top (required)>'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap.rb:61:in `require'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap.rb:61:in `register_rails_engine'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap.rb:11:in `load!'
hdm  | /usr/local/bundle/gems/bootstrap-4.6.1/lib/bootstrap.rb:75:in `<top (required)>'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:60:in `require'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:55:in `each'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:55:in `block in require'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:44:in `each'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler/runtime.rb:44:in `require'
hdm  | /usr/local/bundle/gems/bundler-2.3.11/lib/bundler.rb:176:in `require'
hdm  | /hdm/config/application.rb:7:in `<top (required)>'
hdm  | /hdm/Rakefile:14:in `require_relative'
hdm  | /hdm/Rakefile:14:in `<top (required)>'
hdm  | /usr/local/bundle/gems/railties-7.0.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
hdm  | /usr/local/bundle/gems/railties-7.0.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
hdm  | /usr/local/bundle/gems/railties-7.0.3/lib/rails/command.rb:51:in `invoke'
hdm  | /usr/local/bundle/gems/railties-7.0.3/lib/rails/commands.rb:18:in `<top (required)>'
hdm  | bin/rails:4:in `require'
hdm  | bin/rails:4:in `<main>'
hdm  | (See full trace by running task with --trace)
…

i fixed this with adding

gem 'mini_racer' # minimal Google V8 JS engine for execjs

or is it better to install nodejs into the container?

Transfer code from hdm-pro to hdm

We decided to have the Open Source Version only.
Any code which is in hdm-pro can be merged into this repo.

This should only be the RBAC part.

Foreman HDM integration

Check possibilities for a HDM-Foreman integration.
Design pattern insist that Foreman is talking to a Smart-Proxy only.

We might need:

  • HDM API
  • HDM Smart-Proxy
  • HDM Foreman Web UI

Foreman HDM WebUI queries information from HDM Smart-Proxy.
HDM Smart-Proxy queries information from HDM API.

Foreman HDM Web UI should display in the same way as we do it in HDM.
User authentication is done by Foreman.

HDM container fails to start "unable to start container process: error during container init: sethostname: invalid argument: unknown"

Following the default and taking the latest HDM module and latest Docker module and including HDM on primary. When it tries to start the container it gets

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: sethostname: invalid argument: unknown
Error: failed to start containers: hdm

Update documentation and Docker build

As we now have removed NodeJS and Yarn, we must update the documentation and the Docker container build.
We also must update the documentatoin in terms of development vs production.

The production env must use precompiled assets.
On development assets are compiled on demand.

Feature Request: Searching for hiera keys

At the moment we can search for environments -> nodes -> hiera keys.

Users want to see in which environment, hierarchies and files a hiera key is made available.

This feature should allow users to select an environment and then search for a key.

The webinterface should show the hiera.yaml hierarchies and mark them if the key is available in an hierarchy (bold, like with the node data).

When klicking on a hierachy, a list with all files should be listed which contain the key.
Files without the key should not be shown.
The value should be shown for each file when klicking on the file name.

View only mode!

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.