You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/22 21:30:04 UTC
[GitHub] [airflow] derkuci opened a new pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
derkuci opened a new pull request #20473:
URL: https://github.com/apache/airflow/pull/20473
Currently the return value from `SSHOperator.execute()` depends on whether `enable_xcom_pickling` is True or False.
* If `enable_xcom_pickling=True`, a `bytes` object is returned.
* otherwise, an `str` object with uuencode is returned.
Later the return value may be stored in XCom and retrieved by other tasks.
This confuses the "consumer" of its XCom messages. They have to also check `enable_xcom_pickling` to know if the result should first be uudecoded. Even worse, they have to know it is generated by an "SSHOperator" because other operators do not do that.
Should we change the behavior to always returning a `str`, without uuencode, as the attached pull request suggests? Is that a sensible thing to do?
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#discussion_r776038635
##########
File path: airflow/providers/ssh/operators/ssh.py
##########
@@ -218,10 +215,7 @@ def execute(self, context=None) -> Union[bytes, str]:
result = self.run_ssh_client_command(ssh_client, self.command)
except Exception as e:
raise AirflowException(f"SSH operator error: {str(e)}")
- enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
- if not enable_pickling:
- result = b64encode(result).decode('utf-8')
- return result
+ return result.decode('utf-8')
Review comment:
How do we know we can decode using utf-8 here? I think the main problem here is that the ssh command might simply return (depend which command you run - very raw bytes, not even encoded-string. For example when you run
`ssh root@host 'cat /bin/bash'` without allocating terminal, you will get content of the file returned. This will work in the old SSH in case of both flags are set:
- with pickling - content of the file will be saver as byte array in xcom
- without pickling - the file content will be base64encoded and then converted to the utf8-string
After the change, this will fail and there is no way to send binary, non-encoded data over SSH.
I can't exactly remember, I tried to find it but I was unable to. However I vaguely recall a discussion that someone had quite a legitimate reason for this - it could be kerberos keytab sent over ssh connection automatically when authorized or something equally "convoluted". There are some "security-ish" approaches where you want to utilize ssh authentication, connect to a server and you receieve binary data.
And the current implementation actually handles this case very well.
Whether it's a legitimate case, that is a different story, but I think we cannot just "scrap" the behaviour. And for sure assuming that the data returned by SSH connection will be utf-8 encoded is wrong.
If we really want to store strings, I'd say we should simply add a "result_encoding" parameter and if it is set, we cold do what you did. But this will add even more complexity to what could be expected from ssh operator.
So I am not really sure if we want to do anyting here :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#discussion_r776038635
##########
File path: airflow/providers/ssh/operators/ssh.py
##########
@@ -218,10 +215,7 @@ def execute(self, context=None) -> Union[bytes, str]:
result = self.run_ssh_client_command(ssh_client, self.command)
except Exception as e:
raise AirflowException(f"SSH operator error: {str(e)}")
- enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
- if not enable_pickling:
- result = b64encode(result).decode('utf-8')
- return result
+ return result.decode('utf-8')
Review comment:
How do we know we can decode using utf-8 here? I think the main problem here is that the ssh command might simply return (depend which command you run) - very raw bytes, not even encoded-string. For example when you run `ssh root@host 'cat /bin/bash'` without allocating terminal, you will get content of the 'bash' binary returned. This will work in the old SSH in case of both flags are set:
- with pickling - content of the file will be saver as byte array in xcom (via pickling)
- without pickling - the file content will be base64encoded and then converted to the utf8-string
After the change, this will fail and there is no way to send binary, non-encoded data over SSH.
I can't exactly remember, I tried to find it but I was unable to, however I vaguely recall a discussion that someone had quite a legitimate reason for this - it could be kerberos keytab sent over ssh connection automatically when authorized or something equally "convoluted". There are some "security-ish" approaches where you want to utilize ssh authentication, connect to a server and you receieve binary data.
And the current implementation actually handles this case very well.
Whether it's a legitimate case, that is a different story, but I think we cannot just "scrap" the behaviour. And for sure assuming that the data returned by SSH connection will be utf-8 encoded is wrong.
If we really want to store strings, I'd say we should simply add a "result_encoding" parameter and if it is set, we cold do what you did. But this will add even more complexity to what could be expected from ssh operator.
So I am not really sure if we want to do anyting here :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] derkuci commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
derkuci commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1000920704
> If I understand this correctly, the change is backward incompatible, right? It does not preclude the possibility, but must be clarified so the next SSH provider version can be released correctly.
You're correct. The change makes `SSHOperator` more consistent with other operators and across configurations (i.e., with and without XCom pickling), but breaks the compatibility with its current behavior (hence the tests were also updated).
I personally believe this is a good thing, but have no clue if it is aligned with the ideas of airflow developers. Hence this PR for discussions. If this is OK with you guys, I will try to fix the doc wherever applicable (best with some help as I am even less familiar with the doc).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#discussion_r776038635
##########
File path: airflow/providers/ssh/operators/ssh.py
##########
@@ -218,10 +215,7 @@ def execute(self, context=None) -> Union[bytes, str]:
result = self.run_ssh_client_command(ssh_client, self.command)
except Exception as e:
raise AirflowException(f"SSH operator error: {str(e)}")
- enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
- if not enable_pickling:
- result = b64encode(result).decode('utf-8')
- return result
+ return result.decode('utf-8')
Review comment:
How do we know we can decode using utf-8 here? I think the main problem here is that the ssh command might simply return (depend which command you run) - very raw bytes, not even encoded-string. For example when you run `ssh root@host 'cat /bin/bash'` without allocating terminal, you will get content of the 'bash' binary returned. This will work in the old SSH in case of both flags are set:
- with pickling - content of the file will be saver as byte array in xcom (via pickling)
- without pickling - the file content will be base64encoded and then converted to the utf8-string
After the change, this will fail and there is no way to send binary, non-encoded data over SSH.
I can't exactly remember, I tried to find it but I was unable to. However I vaguely recall a discussion that someone had quite a legitimate reason for this - it could be kerberos keytab sent over ssh connection automatically when authorized or something equally "convoluted". There are some "security-ish" approaches where you want to utilize ssh authentication, connect to a server and you receieve binary data.
And the current implementation actually handles this case very well.
Whether it's a legitimate case, that is a different story, but I think we cannot just "scrap" the behaviour. And for sure assuming that the data returned by SSH connection will be utf-8 encoded is wrong.
If we really want to store strings, I'd say we should simply add a "result_encoding" parameter and if it is set, we cold do what you did. But this will add even more complexity to what could be expected from ssh operator.
So I am not really sure if we want to do anyting here :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1000681382
If I understand this correctly, the change is backward incompatible, right? It does not preclude the possibility, but must be clarified so the next SSH provider version can be released correctly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] derkuci commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
derkuci commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1002268405
Good point! Let's abandon the changes.
My real point always has been that the `xcom_pull` result should be consistent, and whether an encoding/decoding is used shouldn't matter to the user. Since `enable_xcom_pickling=False` (which uses json) is quite limited in the data types that can be serialized, we chose to uuencode the return value from the `SSHOperator`, which causes the inconsistency. It works, though, as you indicated.
However, if "arbitrary binary return value" + "json serialization" is what we want to support, we should wrap json to deal with binary data, instead of forcing `SSHOperator` to do the encode work --- what about other operators that may return binary data?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#discussion_r776038635
##########
File path: airflow/providers/ssh/operators/ssh.py
##########
@@ -218,10 +215,7 @@ def execute(self, context=None) -> Union[bytes, str]:
result = self.run_ssh_client_command(ssh_client, self.command)
except Exception as e:
raise AirflowException(f"SSH operator error: {str(e)}")
- enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
- if not enable_pickling:
- result = b64encode(result).decode('utf-8')
- return result
+ return result.decode('utf-8')
Review comment:
How do we know we can decode using utf-8 here? I think the main problem here is that the ssh command might simply return (depend which command you run) - very raw bytes, not even encoded-string. For example when you run `ssh root@host 'cat /bin/bash'` without allocating terminal, you will get content of the file returned. This will work in the old SSH in case of both flags are set:
- with pickling - content of the file will be saver as byte array in xcom
- without pickling - the file content will be base64encoded and then converted to the utf8-string
After the change, this will fail and there is no way to send binary, non-encoded data over SSH.
I can't exactly remember, I tried to find it but I was unable to. However I vaguely recall a discussion that someone had quite a legitimate reason for this - it could be kerberos keytab sent over ssh connection automatically when authorized or something equally "convoluted". There are some "security-ish" approaches where you want to utilize ssh authentication, connect to a server and you receieve binary data.
And the current implementation actually handles this case very well.
Whether it's a legitimate case, that is a different story, but I think we cannot just "scrap" the behaviour. And for sure assuming that the data returned by SSH connection will be utf-8 encoded is wrong.
If we really want to store strings, I'd say we should simply add a "result_encoding" parameter and if it is set, we cold do what you did. But this will add even more complexity to what could be expected from ssh operator.
So I am not really sure if we want to do anyting here :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1002337416
Yah I see where it came from :)
> * "run_as_user" is broken (at least for us) in the new version. We had to switch some `PythonOperator` to `BashOperator` (use sudo in our script) or, occasionally, `SSHOperator`.
Yeah. I think that one will be fixed in 2.2.4 (or at least there is a work in progress).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk edited a comment on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk edited a comment on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1002275764
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] derkuci closed pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
derkuci closed pull request #20473:
URL: https://github.com/apache/airflow/pull/20473
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1002275764
> My real point always has been that the `xcom_pull` result should be consistent, and whether an encoding/decoding is used shouldn't matter to the user. Since `enable_xcom_pickling=False` (which uses json) is quite limited in the data types that can be serialized, we chose to uuencode the return value from the `SSHOperator`, which causes the inconsistency. It works, though, as you indicated.
I just wonder, why do you think it should be consistent? We do not have auto-discovery of types and format of the returned values in Airflow. Airlfow is task-based not data-based, so basicaly in case you want to pass data between tasks both producer and consumer has to agree on naming conventions and data format used. There is no "universal" discovery. Also even in the case you started with - the "pickling" is deprecated and actually it should be set "per installlation". So it could be that in different installations, different format is used, but it will be "constistent" for that installation. I do not see huge value in providing "consistent" output format really in this case.
> However, if "arbitrary binary return value" + "json serialization" is what we want to support, we should wrap json to deal with binary data, instead of forcing `SSHOperator` to do the encode work --- what about other operators that may return binary data?
I do not think we need to do it. Again this is something we do not reallu want to support via json serialization. SSH is an outlier here indeed. We deliberately only support "json-serializable" objects in default XCom implementation. And possibility of supporting binary storage is implemented already via cusom XCom backends. See here for a well explained example https://www.astronomer.io/guides/custom-xcom-backends
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#discussion_r776038635
##########
File path: airflow/providers/ssh/operators/ssh.py
##########
@@ -218,10 +215,7 @@ def execute(self, context=None) -> Union[bytes, str]:
result = self.run_ssh_client_command(ssh_client, self.command)
except Exception as e:
raise AirflowException(f"SSH operator error: {str(e)}")
- enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
- if not enable_pickling:
- result = b64encode(result).decode('utf-8')
- return result
+ return result.decode('utf-8')
Review comment:
How do we know we can decode using utf-8 here? I think the main problem here is that the ssh command might simply return (depend which command you run) - very raw bytes, not even encoded-string. For example when you run `ssh root@host 'cat /bin/bash'` without allocating terminal, you will get content of the 'bash' binary returned. This will work in the old SSH in case of both flags are set:
- with pickling - content of the file will be saver as byte array in xcom
- without pickling - the file content will be base64encoded and then converted to the utf8-string
After the change, this will fail and there is no way to send binary, non-encoded data over SSH.
I can't exactly remember, I tried to find it but I was unable to. However I vaguely recall a discussion that someone had quite a legitimate reason for this - it could be kerberos keytab sent over ssh connection automatically when authorized or something equally "convoluted". There are some "security-ish" approaches where you want to utilize ssh authentication, connect to a server and you receieve binary data.
And the current implementation actually handles this case very well.
Whether it's a legitimate case, that is a different story, but I think we cannot just "scrap" the behaviour. And for sure assuming that the data returned by SSH connection will be utf-8 encoded is wrong.
If we really want to store strings, I'd say we should simply add a "result_encoding" parameter and if it is set, we cold do what you did. But this will add even more complexity to what could be expected from ssh operator.
So I am not really sure if we want to do anyting here :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] derkuci commented on pull request #20473: SSHOperator.execute() returns str regardless of enable_xcom_pickling
Posted by GitBox <gi...@apache.org>.
derkuci commented on pull request #20473:
URL: https://github.com/apache/airflow/pull/20473#issuecomment-1002333155
> I just wonder, why do you think it should be consistent? We do not have auto-discovery of types and format of the returned values in Airflow. Airlfow is task-based not data-based, so basicaly in case you want to pass data between tasks both producer and consumer has to agree on naming conventions and data format used. There is no "universal" discovery. Also even in the case you started with - the "pickling" is deprecated and actually it should be set "per installlation". So it could be that in different installations, different format is used, but it will be "constistent" for that installation. I do not see huge value in providing "consistent" output format really in this case.
Got you. Our particular case indeed involves "installation" change: upgrading from an old version of airflow to the current version.
* We recently upgraded from 1.9 to 2.2... `enbale_xcom_pickling` was True with the old version, and I hesitated whether I should keep the old value, or switch to "False" as suggested (safety, etc.).
* "run_as_user" is broken (at least for us) in the new version. We had to switch some `PythonOperator` to `BashOperator` (use sudo in our script) or, occasionally, `SSHOperator`.
While we are experimenting with all these changes, we had to deal with uncertainties in the XCom data type/formats. My patch is not general enough (as you kindly explained) but served us well during the upgrade process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org