Conversation
Update dependencies: * Update safety requirement from ~=2.2 to ~=2.3 in /.dev (EMMC-ASBL#187) * Update `requirements.txt` (EMMC-ASBL#188) Update `pre-commit` hooks. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
CasperWA
left a comment
There was a problem hiding this comment.
Some suggested changes here, but I really like this idea of passing in the authentication classes/functions in this way.
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
…rieval of atoken from request-header in to configs of resource, function and transformation
…, change un-call dependency when is initiated during app-startup
…ices into enh/add_auth
|
I added a unit test for checking the retrieval of the token from the configs or the request headers and then through the cache again.
We probably need to specify the An example for the encoding might look like this: In order to prevent the revealing of secrets in the cache through the services, I made the exposure of the redis-cache endpoint optional, since I think this might not be desired in various production scenarios as explained in the |
|
Hmm, I can't immediately penetrate the test error messages. Do you mind if I take a stab at it locally and commit a fix, if I find one? Otherwise I'll just let you know the issue and you could commit :) Edit: I see the issue now. The tests simply needs to be updated to use the new SecretConfig gig you setup. I think that's easier for you to fix, no? :) |
|
Hi @CasperWA, I can reproduce locally. But I am puzzled what is the difference to the previous dev-version of the |
…ce models are serialized. Add http-exception to redisadmin
|
@CasperWA, I have figured out the issue. The route in the Nevertheless, the |
Codecov ReportBase: 68.62% // Head: 69.15% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #189 +/- ##
==========================================
+ Coverage 68.62% 69.15% +0.53%
==========================================
Files 18 18
Lines 494 522 +28
==========================================
+ Hits 339 361 +22
- Misses 155 161 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Ensure objects are JSON serializeable in DummyCache.
| OTEAPI_INCLUDE_REDISADMIN: "${OTEAPI_INCLUDE_REDISADMIN:-False}" | ||
| OTEAPI_EXPOSE_SECRETS: "${OTEAPI_EXPOSE_SECRETS:-True}" |
There was a problem hiding this comment.
Wait. So by default you don't want to include the Redis admin endpoint (for security reasons) but do want to expose secrets? :/
There was a problem hiding this comment.
Well, the redis admin is not exposed because the secrets are exposed.
If the secret strings for the oteapi.models are not exposed, they cannot be read in the strategies anymore, since they are censored during serialization. This pretty much makes them useless if you want to use them for connecting to an external host.
If they are exposed and the redis admin is enabled, you may simply reveal all user's in a configuration through the redis endpoint.
For this reason, the chance, that you may remotely inspect the redis-cache from other's users sessions, is lowered since you only can access the redis-cache from the strategies, and not directly through the services anymore.
In other words, the motivation is that when you put sensitive/general information into the cache, you cannot reveal it by chance if you only got the config-id, but it still can be used by the strategies internally.
Since I did not find any straight-forward user management for redis through an oauth-scheme, I think this is one of the only ways how to deal with this scenario for the moment.
Does this make sense to you?
There was a problem hiding this comment.
This makes sense. Essentially what we need is to hash/encrypt the secrets before storing in redis. That should solve it. The strategies can then get some interface to decrypting the secrets they may need. Or it's done from the service before invoking the strategies. Not very important, but it should circumvent this issue.
However that's something for another day and another PR.
|
@MBueschelberger Could you comment on the last part, Then this can be merged and I can look at the OTELib PR that depends on this. |
|
@MBueschelberger merge at will :) |
… add auth-dependencies during app-launch (#189) * add auth * improve checking if auth enabled * update generic import of authentication dependencies * [Auto-generated] Update dependencies (#190) Update dependencies: * Update safety requirement from ~=2.2 to ~=2.3 in /.dev (#187) * Update `requirements.txt` (#188) Update `pre-commit` hooks. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update docker-compose.yml Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update docker-compose_dev.yml Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * Update app/main.py Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> * resolve importing dependencies for fastapi from env-variable, add retrieval of atoken from request-header in to configs of resource, function and transformation * resolve unknown attribute name in AppSettings * update env-variables in docker-compose * debug forwarding of secrets in function and transformation secrets, add pytests * rename function for pytests * update oteapi-core commit sha, update variable name in docker-compose, change un-call dependency when is initiated during app-startup * update setting of secret-attribute in pydantic models * add option to exclude redisadmin-router on production * update version for oteapi-core, update model-attributes, add settings-parent class * upgrade oteapi-core * update requirements.txt * update DummyCache for pytests: values in cache should be strings, since models are serialized. Add http-exception to redisadmin * Clean up conftest file Ensure objects are JSON serializeable in DummyCache. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: TEAM 4.0[bot] <Team4.0@SINTEF.no> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> Co-authored-by: Casper Welzel Andersen <casper.w.andersen@sintef.no>
Description:
This PR shall represent a draft for adding a potential authentication layer based on
fastapi.securityto the FastApi-app.For this procedure, the
OTEAPI_AUTH_DEPS-env can be enabled, which underlies a similar syntax like theOTEAPI_PLUGIN_PACKAGES-variable. The major difference is that the single modules are referencing to the individual class of the Python-package-regex:my_package.my_module.my_class.Of course, one has to be careful hiding the
OTEAPI_AUTH_DEPS-variable to the outside world, since it may lead to similar security concerns such as theOTEAPI_PLUGIN_PACKAGES-env.An example of the overall variable my look like that:
my_module.my_class | my_other_module.my_other_classWhen this example variable will be parsed during start-up of the app,
my_classandmy_other_classwill be imported and hence result in:FastApi(dependencies=[Depends(my_class()), Depends(my_other_class))]This gives the flexibility that a developer can come up with its own authentication scheme.
Moreover,
my_classormy_classmight be a childclass of the common classes from thefastapi.security-module such asHTTPBasicorHTTPBearerand can provide a callback-function by overriding the__call__-method:The token from the auth.credentials may then be further used for authentication to
OntoRecetc.I am keen towards your feedback and suggestions for improvement!
Type of change:
Checklist for the reviewer:
This checklist should be used as a help for the reviewer.