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

Creds management #53

Merged
merged 41 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ba27771
add rm
zhenik Nov 9, 2020
1ed3d53
bump minio ~> 0.3.0
zhenik Nov 9, 2020
a253826
add vault provider block
zhenik Nov 9, 2020
9d9f47f
fmt formatting
zhenik Nov 9, 2020
37fffbd
mv user provided creds example
zhenik Nov 9, 2020
b0545f1
refactor ansible playbooks
zhenik Nov 9, 2020
f51c571
refactor example with user-provided
zhenik Nov 9, 2020
dddc276
enable nomad -> vault; create kv policy
zhenik Nov 9, 2020
c442b95
add port to output
zhenik Nov 9, 2020
287b10e
update vars and main module
zhenik Nov 9, 2020
2079b20
update changelog
zhenik Nov 9, 2020
0c1095c
add vault-provided-creds example
zhenik Nov 9, 2020
b19e596
fix linter
zhenik Nov 9, 2020
d7d85a5
fix policies rendering
zhenik Nov 9, 2020
99c491d
update tests
zhenik Nov 9, 2020
c5128b0
add until stmt
zhenik Nov 9, 2020
6aca8de
update main doc
zhenik Nov 9, 2020
7e99c0d
update READMEs
zhenik Nov 9, 2020
5072847
Update README.md
zhenik Nov 10, 2020
b6b2c17
Update README.md
zhenik Nov 10, 2020
201e805
Update README.md
zhenik Nov 10, 2020
727ae0a
Update dev/vagrant/conf/nomad/00-enable_vault.hcl
zhenik Nov 10, 2020
76a9ba9
Update example/README.md
zhenik Nov 10, 2020
b3a4c9e
Update example/standalone-user-provided-creds/README.md
zhenik Nov 10, 2020
8247c50
Update example/standalone-user-provided-creds/README.md
zhenik Nov 10, 2020
25eda9c
update input and output
zhenik Nov 10, 2020
652b534
Update README.md
zhenik Nov 10, 2020
0b4caf4
rm redundant line
zhenik Nov 10, 2020
18d7263
rm vault_addr
zhenik Nov 10, 2020
221109d
update variable's names
zhenik Nov 10, 2020
510a325
formatting with terraform fmt
zhenik Nov 10, 2020
41c1efc
use canaries & use host volumes in all examples
zhenik Nov 10, 2020
8b88e0a
Update example/standalone-vault-provided-creds/README.md
zhenik Nov 10, 2020
0999499
Update README.md
zhenik Nov 10, 2020
904ad9d
Update README.md
zhenik Nov 10, 2020
b35f672
Update README.md
zhenik Nov 10, 2020
b917006
Update README.md
zhenik Nov 10, 2020
1d132c3
Update README.md
zhenik Nov 10, 2020
f15efa3
add resources proxy to example
zhenik Nov 10, 2020
e2e8d9d
update documentation example
zhenik Nov 10, 2020
08f681a
update contributors list
zhenik Nov 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add intentions section in readme #42
- Update box ~> 0.7.x #45
- Resource allocation variables for proxy #54
- Improve credentials management (vault provided credentials) #44
- Bump example: minio ~> 0.3.0 #51
- Bump example: postgres ~> 0.3.0 #51
- Output variable for port #49

### Changed

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ destroy-box:
remove-tmp:
rm -rf ./tmp
rm -rf ./.vagrant
rm -rf ./dev/tmp
rm -rf ./.minio.sys
rm -rf ./example/**/.terraform
rm -rf ./example/**/terraform.tfstate
rm -rf ./example/**/terraform.tfstate.backup
rm -rf ./example/**/.terraform*

clean: destroy-box remove-tmp

Expand Down
206 changes: 126 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@ This module is IaC - infrastructure as code which contains a nomad job of [hive]

## Content
0. [Prerequisites](#prerequisites)
1. [Compatibility](#compatibility)
2. [Requirements](#requirements)
1. [Required software](#required-software)
3. [Usage](#usage)
1. [Providers](#providers)
2. [Intentions](#intentions)
4. [Inputs](#inputs)
5. [Outputs](#outputs)
6. [Modes](#modes)
7. [Example](#example)
1. [Requirements](#requirements)
1. [Required modules](#required-modules)
2. [Required software](#required-software)
3. [Compatibility](#compatibility)
4. [Providers](#providers)
5. [Usage](#usage)
1. [Verifying setup](#verifying-setup)
1. [Data example upload](#data-example-upload)
8. [Authors](#authors)
9. [License](#license)
10. [References](#references)
6. [Intentions](#intentions)
7. [Inputs](#inputs)
8. [Outputs](#outputs)
8. [Modes](#modes)
9. [Examples](#examples)
10. [Contributors](#contributors)
11. [License](#license)
12. [References](#references)

## Prerequisites
Please follow [this section in original template](https://github.com/fredrikhgrelland/vagrant-hashistack-template#install-prerequisites)

## Requirements

### Required modules
|Module|Version|
|:---|:---|
|[terraform-nomad-minio](https://github.com/fredrikhgrelland/terraform-nomad-minio)| 0.3.0 or newer|
|[terraform-nomad-postgres](https://github.com/fredrikhgrelland/terraform-nomad-postgres)| 0.3.0 or newer|

### Required software
- [GNU make](https://man7.org/linux/man-pages/man1/make.1.html)
- [Docker](https://www.docker.com/)
- [Consul](https://releases.hashicorp.com/consul/)

## Compatibility
|Software|OSS Version|Enterprise Version|
|:---|:---|:---|
Expand All @@ -34,23 +48,36 @@ Please follow [this section in original template](https://github.com/fredrikhgre
|Vault|1.5.2.1 or newer|1.5.2.1 or newer|
|Nomad|0.12.3 or newer|0.12.3 or newer|

## Requirements

### Required software
All software is provided and run with docker.
See the [Makefile](Makefile) for inspiration.
## Providers
- [Nomad](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs)
- [Vault](https://registry.terraform.io/providers/hashicorp/vault/latest/docs)

## Usage
The following command will run hive in the [example/standalone](example/standalone) folder.
The following command will run hive in the [example/standalone-vault-provided-creds](example/standalone-vault-provided-creds) folder.

```sh
make up
```

### Providers
- [Nomad](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs)
- [Vault](https://registry.terraform.io/providers/hashicorp/vault/latest/docs)
### Verifying setup
You can verify the setup by connection to Hive using the Nomad UI at [localhost:4646](http://localhost:4646/). Follow the steps below.
1. Locate and click the *hive-metastore* service.
2. Click the *exec* button and connect to the *metastoreserver* task.
3. Run `beeline -u jdbc:hive2://` to connect to hive.
4. Run `SHOW databases;`. Your output should look like this:
```sh
OK
+----------------+
| database_name |
+----------------+
| default |
+----------------+
```

#### Data example upload
Check [example/README.md#data-example-upload](example/README.md#data-example-upload)

### Intentions
## Intentions
Module is deployed with [service mesh approach using consul-connect integration](https://www.consul.io/docs/connect), where [communication `service-to-service` controlled by intentions](https://learn.hashicorp.com/tutorials/consul/get-started-service-networking#control-communication-with-intentions).
Intentions are required **`only`** when [consul acl is enabled and default_policy is deny](https://learn.hashicorp.com/tutorials/consul/access-control-setup-production#enable-acls-on-the-agents).

Expand All @@ -76,99 +103,130 @@ In the examples, intentions are created in the Ansible playboook [00_create_inte
| hive\_container\_port | Hive container port | number | 9083 | no |
| hive\_docker\_image | Hive container image | string | "fredrikhgrelland/hive:3.1.0" | no |
| hive\_container\_environment\_variables | Hive environment variables | list(string) | [""] | no |
| resource | Resource allocations | object | - | no |
| resource.cpu | Resource allocation - cpu | number | 500 | no |
| resource.memory | Resource allocation - memory | number | 1024 | no |
| resource_proxy | Resource allocations for proxy | object | - | no |
| resource_proxy.cpu | Resource allocation for proxy - cpu | number | 200 | no |
| resource_proxy.memory | Resource allocation for proxy - memory | number | 128 | no |
| hive\_bucket | Hive requires minio buckets | obj(string) | { default = string, hive = string } | no |
| minio\_service | Minio data-object contains service_name, port, access_key and secret_key | obj(string) | { service_name = string, port = number, access_key = string, secret_key = string } | no |
| postgres\_service | Postgres data-object contains service_name, port, database_name, username and password | obj(string) | { service_name = string, port = number, database_name = string, username = string, password = string } | no |
| resource | Resource allocations for cpu and memory | obj(number, number) | { <br> cpu = 500, <br> memory = 1024 <br> } | no |
| resource\_proxy | Resource allocations for proxy | obj(number, number) | { <br> cpu = 200, <br> memory = 128} <br> | no |
| hive\_bucket | Hive requires minio buckets | obj(string, string) | { <br> default = string, <br> hive = string <br> } | no |
| minio\_service | Minio data-object contains service_name, port, access_key and secret_key | obj(string, number, string, string) | - | no |
| minio\_vault\_secret | Minio data-object contains vault related information to fetch credentials | obj(bool, string, string, string, string) | { <br> use_vault_provider = false, <br> vault_kv_policy_name = "kv-secret", <br> vault_kv_path = "secret/path/to/minio/creds", <br> vault_kv_access_key_name = "access_key", <br> vault_kv_secret_key_name = "secret_key" <br> } | no |
| postgres\_service | Postgres data-object contains service_name, port, database_name, username and password | obj(string, number, string, string, string) | | no |
| postgres\_vault\_secret | Postgres data-object contains vault related information to fetch credentials | obj(bool, string, string, string, string) | { <br> use_vault_provider = false, <br> vault_kv_policy_name = "kv-secret", <br> vault_kv_path = "secret/path/to/postgres/creds", <br> vault_kv_username_name = "username", <br> vault_kv_password_name = "password" <br> } | no |

## Outputs
| Name | Description | Type |
|------|-------------|------|
| service\_name | Hive service name | string |
| buckets | Minio buckets for hive | string |
| port | Hive service port | number |

## Modes
Hive can be run in two modes:
- [hivemetastore](./docker/bin/hivemetastore)
- [hiveserver](./docker/bin/hiveserver)

`NB!` current implementation supports only [`hivemetastore`](conf/nomad/hive.hcl#L104)
**NB!** current implementation supports only [`hivemetastore`](conf/nomad/hive.hcl#110)

## Examples
Folder [example](example) contains examples of module usage, please refer for more details.

## Example
The example-code shows the minimum of what you need do to set up this module.
```hcl-terraform
```hcl
module "minio" {
source = "github.com/fredrikhgrelland/terraform-nomad-minio.git?ref=0.1.0"
source = "github.com/fredrikhgrelland/terraform-nomad-minio.git?ref=0.3.0"

# nomad
nomad_datacenters = ["dc1"]
nomad_namespace = "default"
nomad_host_volume = "persistence-minio"

# minio
service_name = "minio"
host = "127.0.0.1"
port = 9000
container_image = "minio/minio:latest"
access_key = "minio"
secret_key = "minio123"
service_name = "minio"
host = "127.0.0.1"
port = 9000
container_image = "minio/minio:latest" # todo: avoid using tag latest in future releases

# user provided credentials
access_key = "minio"
secret_key = "minio123"
vault_secret = {
use_vault_provider = false,
vault_kv_policy_name = "",
vault_kv_path = "",
vault_kv_access_key = "",
vault_kv_secret_key = ""
}

data_dir = "/minio/data"
buckets = ["default", "hive"]
container_environment_variables = ["JUST_EXAMPLE_VAR1=some-value", "ANOTHER_EXAMPLE2=some-other-value"]
resource = {
cpu = 500,
memory = 1024
}
use_host_volume = true
use_canary = true

# mc
mc_service_name = "mc"
mc_container_image = "minio/mc:latest"
mc_container_image = "minio/mc:latest" # todo: avoid using tag latest in future releases
mc_container_environment_variables = ["JUST_EXAMPLE_VAR3=some-value", "ANOTHER_EXAMPLE4=some-other-value"]
}

module "postgres" {
source = "github.com/fredrikhgrelland/terraform-nomad-postgres.git?ref=0.1.0"
source = "github.com/fredrikhgrelland/terraform-nomad-postgres.git?ref=0.3.0"

# nomad
nomad_datacenters = ["dc1"]
nomad_namespace = "default"
nomad_host_volume = "persistence-postgres"

# postgres
service_name = "postgres"
container_image = "postgres:12-alpine"
container_port = 5432
service_name = "postgres"
container_image = "postgres:12-alpine"
container_port = 5432
vault_secret = {
use_vault_provider = false,
vault_kv_policy_name = "",
vault_kv_path = "",
vault_kv_username_name = "",
vault_kv_password_name = ""
}
admin_user = "hive"
admin_password = "hive"
database = "metastore"
container_environment_variables = ["PGDATA=/var/lib/postgresql/data"]
volume_destination = "/var/lib/postgresql/data"
use_host_volume = true
use_canary = true
container_environment_variables = ["PGDATA=/var/lib/postgresql/data/"]
}

module "hive" {
source = "./.."
source = "../.."

# nomad
nomad_datacenters = ["dc1"]
nomad_namespace = "default"
local_docker_image = false
nomad_datacenters = ["dc1"]
nomad_namespace = "default"
local_docker_image = false

# hive
use_canary = false
use_canary = true
hive_service_name = "hive-metastore"
hive_container_port = 9083
hive_docker_image = "fredrikhgrelland/hive:3.1.0"
hive_container_environment_variables = ["SOME_EXAMPLE=example-value"]

resource = {
cpu = 500,
memory = 1024
}
resource_proxy = {
cpu = 200,
memory = 128
}

# hive - minio
hive_bucket = {
default = "default",
hive = "hive"
default = "default",
hive = "hive"
}
minio_service = {
service_name = module.minio.minio_service_name,
port = 9000,
port = module.minio.minio_port,
access_key = module.minio.minio_access_key,
secret_key = module.minio.minio_secret_key,
}
Expand All @@ -189,26 +247,14 @@ module "hive" {
}
```

### Verifying setup

You can verify the setup by connection to Hive using the Nomad UI at [localhost:4646](http://localhost:4646/). Follow the steps below.
1. Locate and click the *hive-metastore* service.
2. Click the *exec* button and connect to the *metastoreserver* task.
3. Run `beeline -u jdbc:hive2://` to connect to hive.
4. Run `SHOW databases;`. Your output should look like this:
```sh
OK
+----------------+
| database_name |
+----------------+
| default |
+----------------+
```

#### Data example upload
Check [example/README.md#data-example-upload](example/README.md#data-example-upload)

## Authors
## Contributors
[<img src="https://avatars0.githubusercontent.com/u/40291976?s=64&v=4">](https://github.com/fredrikhgrelland)
[<img src="https://avatars2.githubusercontent.com/u/29984156?s=64&v=4">](https://github.com/claesgill)
[<img src="https://avatars3.githubusercontent.com/u/15572799?s=64&v=4">](https://github.com/zhenik)
[<img src="https://avatars3.githubusercontent.com/u/67954397?s=64&v=4">](https://github.com/Neha-Sinha2305)
[<img src="https://avatars3.githubusercontent.com/u/71001093?s=64&v=4">](https://github.com/dangernil)
[<img src="https://avatars1.githubusercontent.com/u/51820995?s=64&v=4">](https://github.com/pdmthorsrud)
[<img src="https://avatars1.githubusercontent.com/u/43400021?s=64&v=4">](https://github.com/hannemariavister)

## License
This work is licensed under Apache 2 License. See [LICENSE](./LICENSE) for full details.
Expand Down
29 changes: 26 additions & 3 deletions conf/nomad/hive.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ job "${service_name}" {
task "metastoreserver" {
driver = "docker"

%{ if use_vault_provider }
vault {
policies = ${vault_kv_policy_name}
}
%{ endif }

%{ if local_docker_image }
artifact {
source = "s3::http://127.0.0.1:9000/dev/tmp/hive_local.tar"
Expand Down Expand Up @@ -139,24 +145,41 @@ CORE_CONF_fs_defaultFS = "s3a://${default_bucket}"
CORE_CONF_fs_s3a_connection_ssl_enabled = false
CORE_CONF_fs_s3a_endpoint = "http://{{ env "NOMAD_UPSTREAM_ADDR_${minio_service_name}" }}"
CORE_CONF_fs_s3a_path_style_access = true
EOH
EOH
}
template {
destination = "local/additional.env"
env = true
data = <<EOH
${envs}
EOH
EOH
}
template {
destination = "secrets/.env"
env = true
data = <<EOH
# MINIO credentials
%{ if minio_use_vault_provider }
{{ with secret "${minio_vault_kv_path}" }}
CORE_CONF_fs_s3a_access_key = "{{ .Data.data.${minio_vault_kv_access_key_name} }}"
CORE_CONF_fs_s3a_secret_key = "{{ .Data.data.${minio_vault_kv_secret_key_name} }}"
{{ end }}
%{ else }
CORE_CONF_fs_s3a_access_key = "${minio_access_key}"
CORE_CONF_fs_s3a_secret_key = "${minio_secret_key}"
%{ endif }

# POSTGRES credentials
%{ if postgres_use_vault_provider }
{{ with secret "${postgres_vault_kv_path}" }}
HIVE_SITE_CONF_javax_jdo_option_ConnectionUserName="{{ .Data.data.${postgres_vault_kv_username_name} }}"
HIVE_SITE_CONF_javax_jdo_option_ConnectionPassword="{{ .Data.data.${postgres_vault_kv_password_name} }}"
{{ end }}
%{ else }
HIVE_SITE_CONF_javax_jdo_option_ConnectionUserName="${postgres_username}"
HIVE_SITE_CONF_javax_jdo_option_ConnectionPassword="${postgres_password}"
EOH
%{ endif }
EOH
}
}
}
Expand Down
Loading