Skip to content

Commit 8573912

Browse files
committed
Pass controller/invoker credentials use env
1 parent 64f968f commit 8573912

File tree

12 files changed

+61
-59
lines changed

12 files changed

+61
-59
lines changed

ansible/roles/controller/tasks/deploy.yml

+3-12
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@
7171
dest: "{{ controller.confdir }}/{{ controller_name }}/jmxremote.access"
7272
mode: 0777
7373

74-
- name: copy controller auth username file
75-
template:
76-
src: "controllerauth.username.j2"
77-
dest: "{{ controller.confdir }}/{{ controller_name }}/controllerauth.username"
78-
mode: 0777
79-
80-
- name: copy controller auth password file
81-
template:
82-
src: "controllerauth.password.j2"
83-
dest: "{{ controller.confdir }}/{{ controller_name }}/controllerauth.password"
84-
mode: 0777
85-
8674
- name: "copy kafka truststore/keystore"
8775
when: kafka.protocol == 'SSL'
8876
copy:
@@ -215,6 +203,9 @@
215203
"CONFIG_whisk_db_activationsFilterDdoc": "{{ db_whisk_activations_filter_ddoc | default() }}"
216204
"CONFIG_whisk_userEvents_enabled": "{{ user_events | default(false) | lower }}"
217205

206+
"CONFIG_whisk_credentials_controller_username": "{{ controller.username }}"
207+
"CONFIG_whisk_credentials_controller_password": "{{ controller.password }}"
208+
218209
"LIMITS_ACTIONS_INVOKES_PERMINUTE": "{{ limits.invocationsPerMinute }}"
219210
"LIMITS_ACTIONS_INVOKES_CONCURRENT": "{{ limits.concurrentInvocations }}"
220211
"LIMITS_TRIGGERS_FIRES_PERMINUTE": "{{ limits.firesPerMinute }}"

ansible/roles/invoker/tasks/deploy.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,6 @@
183183
dest: "{{ invoker.confdir }}/{{ invoker_name }}/jmxremote.access"
184184
mode: 0777
185185

186-
- name: copy invoker auth username file
187-
template:
188-
src: "invokerauth.username.j2"
189-
dest: "{{ invoker.confdir }}/invoker{{ groups['invokers'].index(inventory_hostname) }}/invokerauth.username"
190-
mode: 0777
191-
192-
- name: copy invoker auth password file
193-
template:
194-
src: "invokerauth.password.j2"
195-
dest: "{{ invoker.confdir }}/invoker{{ groups['invokers'].index(inventory_hostname) }}/invokerauth.password"
196-
mode: 0777
197-
198186
- name: add additional jvm params if jmxremote is enabled
199187
when: jmx.enabled
200188
set_fact:
@@ -278,6 +266,8 @@
278266
"CONFIG_whisk_timeLimit_min": "{{ limit_action_time_min | default() }}"
279267
"CONFIG_whisk_timeLimit_max": "{{ limit_action_time_max | default() }}"
280268
"CONFIG_whisk_timeLimit_std": "{{ limit_action_time_std | default() }}"
269+
"CONFIG_whisk_credentials_invoker_username": "{{ invoker.username }}"
270+
"CONFIG_whisk_credentials_invoker_password": "{{ invoker.password }}"
281271
"CONFIG_whisk_concurrencyLimit_min": "{{ limit_action_concurrency_min | default() }}"
282272
"CONFIG_whisk_concurrencyLimit_max": "{{ limit_action_concurrency_max | default() }}"
283273
"CONFIG_whisk_concurrencyLimit_std": "{{ limit_action_concurrency_std | default() }}"

ansible/templates/controllerauth.password.j2

-1
This file was deleted.

ansible/templates/controllerauth.username.j2

-1
This file was deleted.

ansible/templates/invokerauth.password.j2

-1
This file was deleted.

ansible/templates/invokerauth.username.j2

-1
This file was deleted.

common/scala/src/main/resources/reference.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ whisk.spi {
2727
EntitlementSpiProvider = org.apache.openwhisk.core.entitlement.LocalEntitlementProvider
2828
AuthenticationDirectiveProvider = org.apache.openwhisk.core.controller.BasicAuthenticationDirective
2929
InvokerProvider = org.apache.openwhisk.core.invoker.InvokerReactive
30-
InvokerServerProvider = org.apache.openwhisk.core.invoker.InvokerServer
30+
InvokerServerProvider = org.apache.openwhisk.core.invoker.DefaultInvokerServer
3131
}
3232

3333
dispatchers {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.openwhisk.common
19+
20+
case class ControllerCredentials(username: String, password: String)
21+
22+
case class InvokerCredentials(username: String, password: String)

common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala

+3
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,7 @@ object ConfigKeys {
265265
val swaggerUi = "whisk.swagger-ui"
266266

267267
val apacheClientConfig = "whisk.apache-client"
268+
269+
val controllerCredentials = "whisk.credentials.controller"
270+
val invokerCredentials = "whisk.credentials.invoker"
268271
}

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala

+11-13
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ import pureconfig.generic.auto._
3131
import spray.json.DefaultJsonProtocol._
3232
import spray.json._
3333
import org.apache.openwhisk.common.Https.HttpsConfig
34-
import org.apache.openwhisk.common.{AkkaLogging, ConfigMXBean, Logging, LoggingMarkers, TransactionId}
35-
import org.apache.openwhisk.core.WhiskConfig
34+
import org.apache.openwhisk.common.{
35+
AkkaLogging,
36+
ConfigMXBean,
37+
ControllerCredentials,
38+
Logging,
39+
LoggingMarkers,
40+
TransactionId
41+
}
42+
import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig}
3643
import org.apache.openwhisk.core.connector.MessagingProvider
3744
import org.apache.openwhisk.core.containerpool.logging.LogStoreProvider
3845
import org.apache.openwhisk.core.database.{ActivationStoreProvider, CacheChangeNotification, RemoteCacheInvalidation}
@@ -165,16 +172,7 @@ class Controller(val instance: ControllerInstanceId,
165172
runtimes,
166173
List(apiV1.basepath()))
167174

168-
private val controllerUsername = {
169-
val source = scala.io.Source.fromFile("/conf/controllerauth.username");
170-
try source.mkString.replaceAll("\r|\n", "")
171-
finally source.close()
172-
}
173-
private val controllerPassword = {
174-
val source = scala.io.Source.fromFile("/conf/controllerauth.password");
175-
try source.mkString.replaceAll("\r|\n", "")
176-
finally source.close()
177-
}
175+
private val controllerCredentials = loadConfigOrThrow[ControllerCredentials](ConfigKeys.controllerCredentials)
178176

179177
/**
180178
* config runtime
@@ -184,7 +182,7 @@ class Controller(val instance: ControllerInstanceId,
184182
(path("config" / "runtime") & post) {
185183
extractCredentials {
186184
case Some(BasicHttpCredentials(username, password)) =>
187-
if (username == controllerUsername && password == controllerPassword) {
185+
if (username == controllerCredentials.username && password == controllerCredentials.password) {
188186
entity(as[String]) { runtime =>
189187
val execManifest = ExecManifest.initialize(runtime)
190188
if (execManifest.isFailure) {

core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InvokerServer.scala core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/DefaultInvokerServer.scala

+12-17
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,33 @@ import akka.actor.ActorSystem
2121
import akka.http.scaladsl.model.StatusCodes
2222
import akka.http.scaladsl.model.headers.BasicHttpCredentials
2323
import akka.http.scaladsl.server.Route
24-
import org.apache.openwhisk.common.{Logging, TransactionId}
24+
import org.apache.openwhisk.common.{InvokerCredentials, Logging, TransactionId}
25+
import org.apache.openwhisk.core.ConfigKeys
2526
import org.apache.openwhisk.core.containerpool.PrewarmingConfig
2627
import org.apache.openwhisk.core.entity.{CodeExecAsString, ExecManifest}
2728
import org.apache.openwhisk.http.BasicRasService
2829

30+
import pureconfig._
31+
import pureconfig.generic.auto._
32+
2933
import scala.concurrent.ExecutionContext
3034

3135
/**
3236
* Implements web server to handle certain REST API calls.
3337
*/
34-
class InvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionContext,
35-
val actorSystem: ActorSystem,
36-
val logger: Logging)
38+
class DefaultInvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionContext,
39+
val actorSystem: ActorSystem,
40+
val logger: Logging)
3741
extends BasicRasService {
3842

39-
val invokerUsername = {
40-
val source = scala.io.Source.fromFile("/conf/invokerauth.username");
41-
try source.mkString.replaceAll("\r|\n", "")
42-
finally source.close()
43-
}
44-
val invokerPassword = {
45-
val source = scala.io.Source.fromFile("/conf/invokerauth.password");
46-
try source.mkString.replaceAll("\r|\n", "")
47-
finally source.close()
48-
}
43+
private val invokerCredentials = loadConfigOrThrow[InvokerCredentials](ConfigKeys.invokerCredentials)
4944

5045
override def routes(implicit transid: TransactionId): Route = {
5146
super.routes ~ {
5247
(path("config" / "runtime") & post) {
5348
extractCredentials {
5449
case Some(BasicHttpCredentials(username, password)) =>
55-
if (username == invokerUsername && password == invokerPassword) {
50+
if (username == invokerCredentials.username && password == invokerCredentials.password) {
5651
entity(as[String]) { prewarmRuntime =>
5752
val execManifest = ExecManifest.initialize(prewarmRuntime)
5853
if (execManifest.isFailure) {
@@ -82,8 +77,8 @@ class InvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionContext,
8277
}
8378
}
8479

85-
object InvokerServer extends InvokerServerProvider {
80+
object DefaultInvokerServer extends InvokerServerProvider {
8681
override def instance(
8782
invoker: InvokerCore)(implicit ec: ExecutionContext, actorSystem: ActorSystem, logger: Logging): BasicRasService =
88-
new InvokerServer(invoker)
83+
new DefaultInvokerServer(invoker)
8984
}

core/standalone/src/main/resources/standalone.conf

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ whisk {
5858
interface = localhost
5959
}
6060

61+
credentials {
62+
controller.username = controller.user
63+
controller.password = controller.pass
64+
}
65+
66+
67+
6168
# Default set of users which are bootstrapped upon start
6269
users {
6370
whisk-system = "789c46b1-71f6-4ed5-8c54-816aa4f8c502:abczO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP"

0 commit comments

Comments
 (0)