Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ OPENC3_REDIS_PORT=6379
OPENC3_REDIS_EPHEMERAL_HOSTNAME=openc3-redis-ephemeral
OPENC3_REDIS_EPHEMERAL_PORT=6380
# Usernames and passwords
# These lines can be removed from this file if available in the host computer environment variables
OPENC3_REDIS_USERNAME=openc3
OPENC3_REDIS_PASSWORD=openc3password
OPENC3_BUCKET_USERNAME=openc3minio
OPENC3_BUCKET_PASSWORD=openc3miniopassword
OPENC3_SERVICE_PASSWORD=openc3service
OPENC3_SR_REDIS_USERNAME=scriptrunner
OPENC3_SR_REDIS_PASSWORD=scriptrunnerpassword
OPENC3_SR_BUCKET_USERNAME=scriptrunnerminio
OPENC3_SR_BUCKET_PASSWORD=scriptrunnerminiopassword
OPENC3_SERVICE_PASSWORD=openc3service
# Build and repository settings
ALPINE_VERSION=3.18
ALPINE_BUILD=3
Expand Down
39 changes: 32 additions & 7 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2023, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand Down Expand Up @@ -111,8 +111,13 @@ services:
max-size: "10m"
max-file: "3"
environment:
- "RAILS_ENV=production"
- "GEM_HOME=/gems"
RAILS_ENV: "production"
GEM_HOME: "/gems"
OPENC3_REDIS_USERNAME: "${OPENC3_REDIS_USERNAME}"
OPENC3_REDIS_PASSWORD: "${OPENC3_REDIS_PASSWORD}"
OPENC3_BUCKET_USERNAME: "${OPENC3_BUCKET_USERNAME}"
OPENC3_BUCKET_PASSWORD: "${OPENC3_BUCKET_PASSWORD}"
OPENC3_SERVICE_PASSWORD: "${OPENC3_SERVICE_PASSWORD}"
env_file:
- ".env"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who wins: environment or env_file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Expand All @@ -136,8 +141,17 @@ services:
max-size: "10m"
max-file: "3"
environment:
- "RAILS_ENV=production"
- "GEM_HOME=/gems"
RAILS_ENV: "production"
GEM_HOME: "/gems"
OPENC3_REDIS_USERNAME: "${OPENC3_REDIS_USERNAME}"
OPENC3_REDIS_PASSWORD: "${OPENC3_REDIS_PASSWORD}"
OPENC3_BUCKET_USERNAME: "${OPENC3_BUCKET_USERNAME}"
OPENC3_BUCKET_PASSWORD: "${OPENC3_BUCKET_PASSWORD}"
OPENC3_SR_REDIS_USERNAME: "${OPENC3_SR_REDIS_USERNAME}"
OPENC3_SR_REDIS_PASSWORD: "${OPENC3_SR_REDIS_PASSWORD}"
OPENC3_SR_BUCKET_USERNAME: "${OPENC3_SR_BUCKET_USERNAME}"
OPENC3_SR_BUCKET_PASSWORD: "${OPENC3_SR_BUCKET_PASSWORD}"
OPENC3_SERVICE_PASSWORD: "${OPENC3_SERVICE_PASSWORD}"
env_file:
- ".env"

Expand Down Expand Up @@ -165,7 +179,12 @@ services:
max-size: "10m"
max-file: "3"
environment:
- "GEM_HOME=/gems"
GEM_HOME: "/gems"
OPENC3_REDIS_USERNAME: "${OPENC3_REDIS_USERNAME}"
OPENC3_REDIS_PASSWORD: "${OPENC3_REDIS_PASSWORD}"
OPENC3_BUCKET_USERNAME: "${OPENC3_BUCKET_USERNAME}"
OPENC3_BUCKET_PASSWORD: "${OPENC3_BUCKET_PASSWORD}"
OPENC3_SERVICE_PASSWORD: "${OPENC3_SERVICE_PASSWORD}"
env_file:
- ".env"
extra_hosts:
Expand Down Expand Up @@ -223,7 +242,13 @@ services:
max-size: "10m"
max-file: "3"
environment:
- "GEM_HOME=/gems"
GEM_HOME: "/gems"
OPENC3_REDIS_USERNAME: "${OPENC3_REDIS_USERNAME}"
OPENC3_REDIS_PASSWORD: "${OPENC3_REDIS_PASSWORD}"
OPENC3_BUCKET_USERNAME: "${OPENC3_BUCKET_USERNAME}"
OPENC3_BUCKET_PASSWORD: "${OPENC3_BUCKET_PASSWORD}"
OPENC3_SR_BUCKET_USERNAME: "${OPENC3_SR_BUCKET_USERNAME}"
OPENC3_SR_BUCKET_PASSWORD: "${OPENC3_SR_BUCKET_PASSWORD}"
env_file:
- ".env"

Expand Down
2 changes: 0 additions & 2 deletions examples/hostinstall/centos7/openc3_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export OPENC3_REDIS_PASSWORD=openc3password
export OPENC3_BUCKET_USERNAME=openc3minio
export OPENC3_BUCKET_PASSWORD=openc3miniopassword

export OPENC3_SERVICE_PASSWORD=openc3service

export OPENC3_SR_REDIS_USERNAME=scriptrunner
export OPENC3_SR_REDIS_PASSWORD=scriptrunnerpassword
export OPENC3_SR_BUCKET_USERNAME=scriptrunnerminio
Expand Down
4 changes: 2 additions & 2 deletions openc3-cosmos-script-runner-api/app/models/running_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ def self.spawn(scope, name, suite_runner = nil, disconnect = false, environment
end
else
process.environment['OPENC3_API_USER'] = ENV['OPENC3_API_USER']
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
process.environment['OPENC3_API_PASSWORD'] = ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_SERVICE_PASSWORD']
process.environment['OPENC3_API_PASSWORD'] = ENV['OPENC3_SERVICE_PASSWORD']
else
raise "No authentication available for script"
end
Expand Down
4 changes: 2 additions & 2 deletions openc3-cosmos-script-runner-api/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def self.process_suite(name, contents, new_process: true, username: nil, scope:)
end
else
process.environment['OPENC3_API_USER'] = ENV['OPENC3_API_USER']
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
process.environment['OPENC3_API_PASSWORD'] = ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_SERVICE_PASSWORD']
process.environment['OPENC3_API_PASSWORD'] = ENV['OPENC3_SERVICE_PASSWORD']
else
raise "No authentication available for script"
end
Expand Down
2 changes: 1 addition & 1 deletion openc3-cosmos-script-runner-api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
Expand Down
6 changes: 3 additions & 3 deletions openc3-redis/users.acl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user healthcheck on nopass -@all +cluster|info +ping
user openc3 on >openc3password allkeys allchannels -@all +@read +@write +@pubsub +@connection +@transaction +info
user scriptrunner on >scriptrunnerpassword resetkeys resetchannels ~running-script* ~*script-locks ~*script-breakpoints ~*openc3_log_messages &_action_cable_internal &script-api:* -@all +@read +@write +@pubsub +@hash +@connection
user admin on >adminpassword +@admin
user openc3 on #022bd57403439b2a3ec0c081cdd35d40a199bbd4ee6fc0e5113edd4fe1c10071 allkeys allchannels -@all +@read +@write +@pubsub +@connection +@transaction +info
user scriptrunner on #e808c74e210256ee7cf3ec165271544167de776d526f7fa94243e5cdcc08b0c1 resetkeys resetchannels ~running-script* ~*script-locks ~*script-breakpoints ~*openc3_log_messages &_action_cable_internal &script-api:* -@all +@read +@write +@pubsub +@hash +@connection
user admin on #749f09bade8aca755660eeb17792da880218d4fbdc4e25fbec279d7fe9f65d70 +@admin
user default off
2 changes: 0 additions & 2 deletions openc3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set OPENC3_REDIS_USERNAME=openc3
set OPENC3_REDIS_PASSWORD=openc3password
set OPENC3_BUCKET_USERNAME=openc3minio
set OPENC3_BUCKET_PASSWORD=openc3miniopassword
set OPENC3_SERVICE_PASSWORD=openc3service
set OPENC3_SR_REDIS_USERNAME=scriptrunner
set OPENC3_SR_REDIS_PASSWORD=scriptrunnerpassword
set OPENC3_SR_BUCKET_USERNAME=scriptrunnerminio
Expand All @@ -31,7 +30,6 @@ OPENC3_REDIS_USERNAME=openc3
OPENC3_REDIS_PASSWORD=openc3password
OPENC3_BUCKET_USERNAME=openc3minio
OPENC3_BUCKET_PASSWORD=openc3miniopassword
OPENC3_SERVICE_PASSWORD=openc3service
OPENC3_SR_REDIS_USERNAME=scriptrunner
OPENC3_SR_REDIS_PASSWORD=scriptrunnerpassword
OPENC3_SR_BUCKET_USERNAME=scriptrunnerminio
Expand Down
2 changes: 1 addition & 1 deletion openc3/lib/openc3/io/json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _generate_url(microservice_name:, prefix:, schema: 'http', hostname: nil, po
# generate the auth object
def _generate_auth
if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil?
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_API_PASSWORD']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENV['OPENC3_SERVICE_PASSWORD'] was never used right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really... at least it shouldn't have been.

return OpenC3Authentication.new()
else
return nil
Expand Down
2 changes: 1 addition & 1 deletion openc3/lib/openc3/io/json_api_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def initialize(url: ENV['OPENC3_API_URL'], timeout: 1.0, authentication: nil)
# generate the auth object
def generate_auth
if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil?
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_API_PASSWORD']
return OpenC3Authentication.new()
else
return nil
Expand Down
16 changes: 4 additions & 12 deletions openc3/lib/openc3/models/auth_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
module OpenC3
class AuthModel
PRIMARY_KEY = 'OPENC3__TOKEN'
SERVICE_KEY = 'OPENC3__SERVICE__TOKEN'

TOKEN_CACHE_TIMEOUT = 5
@@token_cache = nil
@@token_cache_time = nil
@@service_token_cache = nil
@@service_token_cache_time = nil

def self.is_set?(key = PRIMARY_KEY)
Store.exists(key) == 1
Expand All @@ -43,20 +40,15 @@ def self.verify(token, permission: nil)

token_hash = hash(token)
return true if @@token_cache and (Time.now - @@token_cache_time) < TOKEN_CACHE_TIMEOUT and @@token_cache == token_hash
return true if @@service_token_cache and (Time.now - @@service_token_cache_time) < TOKEN_CACHE_TIMEOUT and @@service_token_cache == token_hash and permission != 'admin'

@@token_cache = Store.get(PRIMARY_KEY)
@@token_cache_time = Time.now
return true if @@token_cache == token_hash

@@service_token_cache = Store.get(SERVICE_KEY)
@@service_token_cache_time = @@token_cache_time
if ENV['OPENC3_SERVICE_PASSWORD'] and hash(ENV['OPENC3_SERVICE_PASSWORD']) != @@service_token_cache
set_hash = hash(ENV['OPENC3_SERVICE_PASSWORD'])
OpenC3::Store.set(SERVICE_KEY, set_hash)
@@service_token_cache = set_hash
end
return true if @@service_token_cache == token_hash and permission != 'admin'
# Handle a service password - Generally only used by ScriptRunner
service_password = ENV['OPENC3_SERVICE_PASSWORD']
return true if service_password and service_password == token and permission != 'admin'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the point of the previous cache and how it is now removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previous code was dumb. It should have just been comparing cleartext versions and not bothering with a hash.


return false
end

Expand Down
4 changes: 2 additions & 2 deletions openc3/lib/openc3/script/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def generate_timeout
# generate the auth object
def generate_auth
if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil?
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_API_PASSWORD']
return OpenC3Authentication.new()
else
return nil
Expand Down Expand Up @@ -292,7 +292,7 @@ def generate_timeout
# generate the auth object
def generate_auth
if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil?
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_API_PASSWORD']
return OpenC3Authentication.new()
else
return nil
Expand Down
2 changes: 1 addition & 1 deletion openc3/lib/openc3/script/web_socket_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def disconnect
# Generate the appropriate token for OpenC3
def generate_auth
if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil?
if ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
if ENV['OPENC3_API_PASSWORD']
return OpenC3Authentication.new()
else
raise "Environment Variables Not Set for Authentication"
Expand Down
4 changes: 2 additions & 2 deletions openc3/lib/openc3/utilities/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class OpenC3AuthenticationRetryableError < OpenC3AuthenticationError; end
# OpenC3 base / open source authentication code
class OpenC3Authentication
def initialize()
@token = ENV['OPENC3_API_PASSWORD'] || ENV['OPENC3_SERVICE_PASSWORD']
@token = ENV['OPENC3_API_PASSWORD']
if @token.nil?
raise OpenC3AuthenticationError, "Authentication requires environment variables OPENC3_API_PASSWORD or OPENC3_SERVICE_PASSWORD"
raise OpenC3AuthenticationError, "Authentication requires environment variable OPENC3_API_PASSWORD"
end
end

Expand Down
2 changes: 0 additions & 2 deletions openc3/python/openc3/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
_openc3_bucket_url = "OPENC3_BUCKET_URL"
_openc3_bucket_username = "OPENC3_BUCKET_USERNAME"
_openc3_bucket_password = "OPENC3_BUCKET_PASSWORD"
_openc3_service_password = "OPENC3_SERVICE_PASSWORD"
_openc3_devel = "OPENC3_DEVEL"
_openc3_full_backtrace = "OPENC3_FULL_BACKTRACE"
_openc3_config_bucket = "OPENC3_CONFIG_BUCKET"
Expand Down Expand Up @@ -104,7 +103,6 @@
OPENC3_BUCKET_URL = os.environ.get(_openc3_bucket_url)
OPENC3_BUCKET_USERNAME = os.environ.get(_openc3_bucket_username)
OPENC3_BUCKET_PASSWORD = os.environ.get(_openc3_bucket_password)
OPENC3_SERVICE_PASSWORD = os.environ.get(_openc3_service_password)
OPENC3_DEVEL = os.environ.get(_openc3_devel)
OPENC3_FULL_BACKTRACE = os.environ.get(_openc3_full_backtrace)
OPENC3_CONFIG_BUCKET = os.environ.get(_openc3_config_bucket)
Expand Down
2 changes: 1 addition & 1 deletion openc3/python/openc3/io/json_api_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, url, timeout=1.0, authentication=None):
# generate the auth object
def generate_auth(self):
if OPENC3_API_TOKEN is None and OPENC3_API_USER is None:
if OPENC3_API_PASSWORD or OPENC3_SERVICE_PASSWORD:
if OPENC3_API_PASSWORD:
return OpenC3Authentication()
else:
return None
Expand Down
2 changes: 1 addition & 1 deletion openc3/python/openc3/script/server_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate_timeout(self):
# generate the auth object
def generate_auth(self):
if OPENC3_API_TOKEN is None and OPENC3_API_USER is None:
if OPENC3_API_PASSWORD or OPENC3_SERVICE_PASSWORD:
if OPENC3_API_PASSWORD:
return OpenC3Authentication()
else:
return None
Expand Down
4 changes: 2 additions & 2 deletions openc3/python/openc3/utilities/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class OpenC3AuthenticationRetryableError(OpenC3AuthenticationError):
# OpenC3 base / open source authentication code
class OpenC3Authentication:
def __init__(self):
self._token = OPENC3_API_PASSWORD or OPENC3_SERVICE_PASSWORD
self._token = OPENC3_API_PASSWORD
if not self._token:
raise OpenC3AuthenticationError(
"Authentication requires environment variables OPENC3_API_PASSWORD or OPENC3_SERVICE_PASSWORD"
"Authentication requires environment variable OPENC3_API_PASSWORD"
)

def token(self):
Expand Down