Skip to content

Commit

Permalink
Merge pull request feast-dev#62 from farfetch-external/isacabe/KE-772…
Browse files Browse the repository at this point in the history
…_redis_password

Redis security (added password to redis)
  • Loading branch information
isabelcabezasm authored Jul 7, 2020
2 parents e862b2e + 045e1ca commit 7f5a42e
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 20 deletions.
7 changes: 7 additions & 0 deletions infra/docker-compose/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ FEAST_CORE_IMAGE=gcr.io/kf-feast/feast-core
FEAST_CORE_CONFIG=core.yml
FEAST_CORE_GCP_SERVICE_ACCOUNT_KEY=placeholder.json

FEAST_JUPYTER_IMAGE=jupyterimage

# Feast Serving
FEAST_SERVING_IMAGE=gcr.io/kf-feast/feast-serving
# Feast Serving - Batch (BigQuery)
Expand All @@ -18,3 +20,8 @@ FEAST_ONLINE_SERVING_CONFIG=online-serving.yml

# Jupyter
FEAST_JUPYTER_GCP_SERVICE_ACCOUNT_KEY=placeholder.json

# Redis
REDIS_HOST=feast_redis_1
# write here the password for your redis container (development environment).
REDIS_PASS=PUT_YOUR_PASSWORD_HERE
2 changes: 2 additions & 0 deletions infra/docker-compose/docker-compose.batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
environment:
GOOGLE_APPLICATION_CREDENTIALS: /etc/gcloud/service-accounts/key.json
FEAST_JOB_STAGING_LOCATION: ${FEAST_BATCH_JOB_STAGING_LOCATION}
REDIS_HOST: ${REDIS_HOST}
REDIS_PASS: ${REDIS_PASS}
command:
- "java"
- "-Xms1024m"
Expand Down
4 changes: 4 additions & 0 deletions infra/docker-compose/docker-compose.online.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ services:
ports:
- 6566:6566
restart: on-failure
environment:
REDIS_PASS: ${REDIS_PASS}
REDIS_HOST: ${REDIS_HOST}
command:
- java
- -jar
Expand All @@ -21,5 +24,6 @@ services:

redis:
image: redis:5-alpine
command: redis-server --requirepass '${REDIS_PASS}'
ports:
- "6379:6379"
3 changes: 2 additions & 1 deletion infra/docker-compose/serving/batch-serving.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ feast:
- name: "*"
project: "*"
job_store:
redis_host: redis
redis_host: ${REDIS_HOST}
redis_pass: '${REDIS_PASS}'
redis_port: 6379

grpc:
Expand Down
3 changes: 2 additions & 1 deletion infra/docker-compose/serving/online-serving.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ feast:
- name: online
type: REDIS
config:
host: redis
host: ${REDIS_HOST}
pass: '${REDIS_PASS}'
port: 6379
subscriptions:
- name: "*"
Expand Down
2 changes: 2 additions & 0 deletions infra/terraform/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ feast-online-serving:
config:
host: ${var.redis_hostname}
port: ${var.redis_port}
pass: ${var.redis_pass}
subscriptions:
- name: "*"
project: "*"
Expand Down Expand Up @@ -293,6 +294,7 @@ feast-batch-serving:
job_store:
redis_host: ${var.redis_hostname}
redis_port: ${var.redis_port}
redis_pass: ${var.redis_pass}
feast-core:
enabled: false
Expand Down
4 changes: 4 additions & 0 deletions infra/terraform/app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ variable "redis_port" {
description = "The port of the Azure Redis Cache instance."
type = number
}
variable "redis_pass" {
description = "The password of the Azure Redis Cache instance."
type = string
}
variable "spark_job_jars" {
description = "The local directory from which Spark job JARs are to be uploaded to DBFS."
type = string
Expand Down
5 changes: 5 additions & 0 deletions infra/terraform/infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ output "redis_hostname" {
output "redis_port" {
value = azurerm_redis_cache.redis_cluster.port
}
output "redis_pass" {
sensitive = true
value = azurerm_redis_cache.redis_cluster.primary_access_key
}

output "databricks_workspace_url" {
value = "https://${azurerm_databricks_workspace.databricks.workspace_url}"
}
Expand Down
1 change: 1 addition & 0 deletions protos/feast/core/Store.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ message Store {
int32 initial_backoff_ms = 3;
// Optional. Maximum total number of retries for connecting to Redis. Default to zero retries.
int32 max_retries = 4;
string pass = 5;
}

message BigQueryConfig {
Expand Down
21 changes: 21 additions & 0 deletions serving/src/main/java/feast/serving/config/FeastProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ public static class JobStoreProperties {
/** Job Store Redis Host */
private int redisPort;

/** Job Store Redis Pass */
private String redisPass;

/**
* Gets redis host.
*
Expand Down Expand Up @@ -476,6 +479,24 @@ public int getRedisPort() {
public void setRedisPort(int redisPort) {
this.redisPort = redisPort;
}

/**
* Gets redis pass.
*
* @return the redis pass
*/
public String getRedisPass() {
return redisPass;
}

/**
* Sets redis pass.
*
* @param redisPass the redis pass
*/
public void setRedisPass(String redisPass) {
this.redisPass = redisPass;
}
}

/** Trace metric collection properties */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class RedisBackedJobService implements JobService {
public RedisBackedJobService(FeastProperties.JobStoreProperties jobStoreProperties) {
RedisURI uri =
RedisURI.create(jobStoreProperties.getRedisHost(), jobStoreProperties.getRedisPort());

uri.setPassword(jobStoreProperties.getRedisPass());
this.syncCommand =
RedisClient.create(DefaultClientResources.create(), uri)
.connect(new ByteArrayCodec())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ public VoidFunction2<Dataset<byte[]>, Long> configure() {
JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
Broadcast<Write> broadcastedWriter = sc.broadcast(write);

return new RedisWriter(
broadcastedWriter,
RedisURI redisuri =
new RedisURI(
redisConfig.getHost(),
redisConfig.getPort(),
java.time.Duration.ofMillis(DEFAULT_TIMEOUT)));
java.time.Duration.ofMillis(DEFAULT_TIMEOUT));
redisuri.setPassword(redisConfig.getPass());

return new RedisWriter(broadcastedWriter, redisuri);
}

@SuppressWarnings("serial")
Expand Down
11 changes: 7 additions & 4 deletions spark/spark-ingestion-job/src/test/java/feast/test/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,13 @@ public static void validateRedis(
Map<RedisKey, FeatureRow> expected = TestUtil.generateExpectedData(featureSet.getSpec(), input);

LOGGER.info("Validating the actual values written to Redis ...");
RedisClient redisClient =
RedisClient.create(
new RedisURI(
redisConfig.getHost(), redisConfig.getPort(), java.time.Duration.ofMillis(2000)));

RedisURI redisuri =
new RedisURI(
redisConfig.getHost(), redisConfig.getPort(), java.time.Duration.ofMillis(2000));
redisuri.setPassword(redisConfig.getPass());

RedisClient redisClient = RedisClient.create(redisuri);
StatefulRedisConnection<byte[], byte[]> connection = redisClient.connect(new ByteArrayCodec());
RedisCommands<byte[], byte[]> sync = connection.sync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public static OnlineRetriever create(Map<String, String> config) {
.map(
hostPort -> {
String[] hostPortSplit = hostPort.trim().split(":");
return RedisURI.create(hostPortSplit[0], Integer.parseInt(hostPortSplit[1]));
RedisURI redisuri =
RedisURI.create(hostPortSplit[0], Integer.parseInt(hostPortSplit[1]));
if (hostPortSplit.length == 3) {
redisuri.setPassword(hostPortSplit[2]);
}
return redisuri;
})
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ private RedisOnlineRetriever(StatefulRedisConnection<byte[], byte[]> connection)
}

public static OnlineRetriever create(Map<String, String> config) {
RedisURI redisuri = RedisURI.create(config.get("host"), Integer.parseInt(config.get("port")));
redisuri.setPassword(config.get("pass"));

StatefulRedisConnection<byte[], byte[]> connection =
RedisClient.create(
RedisURI.create(config.get("host"), Integer.parseInt(config.get("port"))))
.connect(new ByteArrayCodec());
RedisClient.create(redisuri).connect(new ByteArrayCodec());

return new RedisOnlineRetriever(connection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public RedisClusterIngestionClient(StoreProto.Store.RedisClusterConfig redisClus
.map(
hostPort -> {
String[] hostPortSplit = hostPort.trim().split(":");
return RedisURI.create(hostPortSplit[0], Integer.parseInt(hostPortSplit[1]));
RedisURI redisuri =
RedisURI.create(hostPortSplit[0], Integer.parseInt(hostPortSplit[1]));
if (hostPortSplit.length == 3) {
redisuri.setPassword(hostPortSplit[2]);
}
return redisuri;
})
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public abstract static class Builder {
@Override
public void prepareWrite(FeatureSet featureSet) {
if (getRedisConfig() != null) {
RedisClient redisClient =
RedisClient.create(
RedisURI.create(getRedisConfig().getHost(), getRedisConfig().getPort()));
RedisURI redisuri = RedisURI.create(getRedisConfig().getHost(), getRedisConfig().getPort());
redisuri.setPassword(getRedisConfig().getPass());
RedisClient redisClient = RedisClient.create(redisuri);

try {
redisClient.connect();
} catch (RedisConnectionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public class RedisStandaloneIngestionClient implements RedisIngestionClient {
private final String host;
private final String pass;
private final int port;
private final BackOffExecutor backOffExecutor;
private RedisClient redisclient;
Expand All @@ -43,15 +44,17 @@ public class RedisStandaloneIngestionClient implements RedisIngestionClient {
public RedisStandaloneIngestionClient(StoreProto.Store.RedisConfig redisConfig) {
this.host = redisConfig.getHost();
this.port = redisConfig.getPort();
this.pass = redisConfig.getPass();
long backoffMs = redisConfig.getInitialBackoffMs() > 0 ? redisConfig.getInitialBackoffMs() : 1;
this.backOffExecutor =
new BackOffExecutor(redisConfig.getMaxRetries(), Duration.millis(backoffMs));
}

@Override
public void setup() {
this.redisclient =
RedisClient.create(new RedisURI(host, port, java.time.Duration.ofMillis(DEFAULT_TIMEOUT)));
RedisURI redisuri = new RedisURI(host, port, java.time.Duration.ofMillis(DEFAULT_TIMEOUT));
redisuri.setPassword(pass);
this.redisclient = RedisClient.create(redisuri);
}

@Override
Expand Down

0 comments on commit 7f5a42e

Please sign in to comment.